Accessing the value of a struct

Discussion in 'C++' started by SteveB, Sep 14, 2006.

  1. SteveB

    SteveB Guest

    Hi

    I have a COM component that passes some udts around.


    The function header is thus:


    void App::passUdt(struct udtSR *pudtSR)


    pudtSR has a member struct called udtValue1 of type udtLONG that has
    the definition:


    struct udtLONG
    {
    long lngValue;
    enum enumVarStatus enmStatus;



    };


    what i want to do is set a LONG to the value stored in the lngValue
    part of udtLONG.

    however if I add


    long lVal = pudtSR.udtValue1.lngValue;


    I get the following error:


    error C2228: left of '.udtValue1' must have class/struct/union type


    Can anyone point me in the right direction ?


    Many thanks


    Steve
    SteveB, Sep 14, 2006
    #1
    1. Advertising

  2. SteveB

    David Harmon Guest

    On 14 Sep 2006 04:26:12 -0700 in comp.lang.c++, "SteveB"
    <> wrote,
    >long lVal = pudtSR.udtValue1.lngValue;
    >
    >I get the following error:
    >
    >error C2228: left of '.udtValue1' must have class/struct/union type


    It's a pointer.

    pudtSR->udtValue1.lngValue;
    or
    (*pudtSR).udtValue1.lngValue;
    David Harmon, Sep 14, 2006
    #2
    1. Advertising

  3. SteveB

    jimmy Guest

    SteveB 写é“:

    > Hi
    >
    > I have a COM component that passes some udts around.
    >
    >
    > The function header is thus:
    >
    >
    > void App::passUdt(struct udtSR *pudtSR)
    >
    >
    > pudtSR has a member struct called udtValue1 of type udtLONG that has
    > the definition:
    >
    >
    > struct udtLONG
    > {
    > long lngValue;
    > enum enumVarStatus enmStatus;
    >
    >
    >
    > };
    >
    >
    > what i want to do is set a LONG to the value stored in the lngValue
    > part of udtLONG.
    >
    > however if I add
    >
    >
    > long lVal = pudtSR.udtValue1.lngValue;

    God, you just so careless to do so.
    Pointers cannot use a dot operator.
    >
    >
    > I get the following error:
    >
    >
    > error C2228: left of '.udtValue1' must have class/struct/union type
    >
    >
    > Can anyone point me in the right direction ?
    >
    >
    > Many thanks
    >
    >
    > Steve
    jimmy, Sep 14, 2006
    #3
  4. SteveB

    SteveB Guest

    David Harmon wrote:
    > On 14 Sep 2006 04:26:12 -0700 in comp.lang.c++, "SteveB"
    > <> wrote,
    > >long lVal = pudtSR.udtValue1.lngValue;
    > >
    > >I get the following error:
    > >
    > >error C2228: left of '.udtValue1' must have class/struct/union type

    >
    > It's a pointer.
    >
    > pudtSR->udtValue1.lngValue;
    > or
    > (*pudtSR).udtValue1.lngValue;


    thank you - that was perfect
    SteveB, Sep 14, 2006
    #4
  5. SteveB

    SteveB Guest

    jimmy wrote:
    > SteveB 写é“:
    >
    > > Hi
    > >
    > > I have a COM component that passes some udts around.
    > >
    > >
    > > The function header is thus:
    > >
    > >
    > > void App::passUdt(struct udtSR *pudtSR)
    > >
    > >
    > > pudtSR has a member struct called udtValue1 of type udtLONG that has
    > > the definition:
    > >
    > >
    > > struct udtLONG
    > > {
    > > long lngValue;
    > > enum enumVarStatus enmStatus;
    > >
    > >
    > >
    > > };
    > >
    > >
    > > what i want to do is set a LONG to the value stored in the lngValue
    > > part of udtLONG.
    > >
    > > however if I add
    > >
    > >
    > > long lVal = pudtSR.udtValue1.lngValue;

    > God, you just so careless to do so.
    > Pointers cannot use a dot operator.
    > >
    > >
    > > I get the following error:
    > >
    > >
    > > error C2228: left of '.udtValue1' must have class/struct/union type
    > >
    > >
    > > Can anyone point me in the right direction ?
    > >
    > >
    > > Many thanks
    > >
    > >
    > > Steve


    thanks for that jimmy.
    SteveB, Sep 14, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RA Scheltema
    Replies:
    3
    Views:
    392
    RA Scheltema
    Jan 6, 2004
  2. Gunnar G

    struct in struct

    Gunnar G, May 31, 2004, in forum: C++
    Replies:
    14
    Views:
    797
  3. DanielEKFA
    Replies:
    8
    Views:
    601
    DanielEKFA
    May 16, 2005
  4. James Harris
    Replies:
    4
    Views:
    1,384
    James Harris
    Oct 9, 2003
  5. Chris Fogelklou
    Replies:
    36
    Views:
    1,371
    Chris Fogelklou
    Apr 20, 2004
Loading...

Share This Page