By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

What is wrong with this?

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"JustSomeGuy" <no**@nottelling.com> wrote...
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'?
Jul 22 '05 #2

P: n/a
JustSomeGuy wrote:
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

Jul 22 '05 #3

P: n/a
JustSomeGuy wrote:

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
Jul 22 '05 #4

P: n/a
"JustSomeGuy" <no**@nottelling.com> wrote in message
news:UPkEb.743236$pl3.58591@pd7tw3no...
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.
Jul 22 '05 #5

P: n/a
where the declaration of variable "iterm"
"JustSomeGuy" <no**@nottelling.com> wrote in message
news:UPkEb.743236$pl3.58591@pd7tw3no...
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

Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.