Can somebody please tell me what is wrong in here or what does this error message means : " error
: reguest for member 'name' in 'person',which is of non-class type 'Person[2]' "

   struct Person{

       int days;
       string name;


   };

const int size = 2;

  bool way_to_Sort(const Person &a, const Person &b) {return a.days < b.days;}

int main()
{
        Person person[size];

          for(int i = 0;i<=size;i++){

            cout << "Please enter a friend : "; 
            cin >> person.name[i];cout << endl; // error here
            cout << "Please enter num of days : "; 
            cin >> person.days[i];cout << endl; // here


          }

       sort(begin(person),end(person),way_to_Sort);

       for(int i = 0;i<size;i++){

          cout << "Names by days : " << person.name[i]<<endl; //here


       }



}

person.name[i]

You need to index person, not name

person[i].name

what a dump mistake. Thanks

Your array is made of Person objects. To select the ith object you would use person[i]. Then you would like to get to the name of this person which would be .name. Combing those you adress your ith name as person[i].name.
The same goes for your days.

The reason for this is that person[i] is a shortcut for value at (startpersonptr + offset i). This gives you your object at index i. This object will be of type Person, and you can use your calls methodes on it, so you can call your .name on it. You can however not call your .name on the array which is what you were trying to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.