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

How to fix error: "request for member which is of non-class type"?

P: 19
Hello,

I am getting the following error

25 C:\Dev-Cpp\main.cpp request for member `no' in `one', which is of non-class type `box[12]'


in the code

Expand|Select|Wrap|Line Numbers
  1. while (!myfile.eof())
  2.    {
  3.  
  4.    for(int i=0;i<12;i++)
  5.    {              
  6.     myfile>>one.no[i];           
  7.    }
  8.  
  9.    }
where 'one' is an object of struct type 'box' and 'no' is the variable inside the struct.

The above bit of code is just the simplified version of my complete code but basically I declared an array of struct type 'box' (size=12) , named it 'one', and am currently reading some numbers from a file into the variable 'no' of the struct.

I would be grateful if someone could let me know the source of the error. Thanks.
Feb 7 '11 #1

✓ answered by newb16

this
.... here 'one' is an object of struct type 'box'
and this...
I declared an array of struct type 'box' (size=12) , named it 'one', ...
are different things. The first one has the member 'no' that can be accessed as one.no ; the second is an array and has to be accessed like
one[1].no

Share this Question
Share on Google+
2 Replies


100+
P: 687
this
.... here 'one' is an object of struct type 'box'
and this...
I declared an array of struct type 'box' (size=12) , named it 'one', ...
are different things. The first one has the member 'no' that can be accessed as one.no ; the second is an array and has to be accessed like
one[1].no
Feb 7 '11 #2

P: 19
Oh! Thanks a lot! :)
Feb 7 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.