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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kino
    New Member
    • Feb 2011
    • 19

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

    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

    Code:
    while (!myfile.eof())
       {
      
       for(int i=0;i<12;i++)
       {              
        myfile>>one.no[i];           
       }
       
       }
    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.
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    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

    Comment

    • kino
      New Member
      • Feb 2011
      • 19

      #3
      Oh! Thanks a lot! :)

      Comment

      Working...