Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Accessing the value of a struct

Reply
Thread Tools

Accessing the value of a struct

 
 
SteveB
Guest
Posts: n/a
 
      09-14-2006
Hi

I have a COM component that passes some udts around.


The function header is thus:


void App:assUdt(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

 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      09-14-2006
On 14 Sep 2006 04:26:12 -0700 in comp.lang.c++, "SteveB"
<(E-Mail Removed)> 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;


 
Reply With Quote
 
 
 
 
jimmy
Guest
Posts: n/a
 
      09-14-2006

SteveB 写道:

> Hi
>
> I have a COM component that passes some udts around.
>
>
> The function header is thus:
>
>
> void App:assUdt(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


 
Reply With Quote
 
SteveB
Guest
Posts: n/a
 
      09-14-2006

David Harmon wrote:
> On 14 Sep 2006 04:26:12 -0700 in comp.lang.c++, "SteveB"
> <(E-Mail Removed)> 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

 
Reply With Quote
 
SteveB
Guest
Posts: n/a
 
      09-14-2006

jimmy wrote:
> SteveB 写道:
>
> > Hi
> >
> > I have a COM component that passes some udts around.
> >
> >
> > The function header is thus:
> >
> >
> > void App:assUdt(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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
Typedef A references struct B which references struct A which... DanielEKFA C++ 8 05-16-2005 10:26 AM
struct in struct Gunnar G C++ 14 06-02-2004 06:43 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
implementing a templated struct within a templated struct RA Scheltema C++ 3 01-06-2004 11:25 AM



Advertisments