What is wrong with this?

J

JustSomeGuy

typedef struct
{
unsigned char item_type;
unsigned char res;
unsigned short item_len;
} item_type;

if (item.item_type != 0x30)

Gives the error:
rq.h(46) : error C2274: 'function-style cast' : illegal as right side of '.'
operator

VC++ 6.0
 
V

Victor Bazarov

JustSomeGuy said:
typedef struct
{
unsigned char item_type;
unsigned char res;
unsigned short item_len;
} item_type;

if (item.item_type != 0x30)

Gives the error:
rq.h(46) : error C2274: 'function-style cast' : illegal as right side of '.'
operator

WTF is 'item'?
 
D

Default User

JustSomeGuy said:
typedef struct

This is unnecessary in C++.
{
unsigned char item_type;
unsigned char res;
unsigned short item_len;
} item_type;

You typdefed the struct to the same name as one of the members? What
exactly are you trying to do here?




Brian Rodenborn
 
T

Thomas Matthews

JustSomeGuy said:
typedef struct
{
unsigned char item_type;
unsigned char res;
unsigned short item_len;
} item_type;

if (item.item_type != 0x30)

Gives the error:
rq.h(46) : error C2274: 'function-style cast' : illegal as right side of '.'
operator

VC++ 6.0
Your compiler may be confused because you have declared
"item_type" as a typedef and also as a member. Try changing
the names:

struct item_struct
{
unsigned char item_ID;
unsigned char res;
unsigned short item_len;
};
Note that in C++, there is no "typedef" required. Also, if you
give us more information about the "big picture", we could tell
you a better method of design that doesn't need to know about
"item_type" or "item_ID" field.

See:
http://www.objectmentor.com/resources/articles/dip.pdf

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
J

JustSomeGuy

JustSomeGuy said:
typedef struct
{
unsigned char item_type;
unsigned char res;
unsigned short item_len;
} item_type;

if (item.item_type != 0x30)

Gives the error:
rq.h(46) : error C2274: 'function-style cast' : illegal as right side of '.'
operator

VC++ 6.0

Sorry... gcc liked this vc++ didn't.
because item_type being the type is the same name as one of its members.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,404
Latest member
PerryRutt

Latest Threads

Top