c++ - Trying to use a member function on a class array -


using code below, want use sort function take student array , sort them based on gpa component. have use parameters of student array , size of array. if towards bottom of int main function try call on member sort sort array a no avail. error is:

member reference base type student [200] not structure or union.

how wrote code take array a , use member sort on given parameters have use. in advance. if please let me know i'll try specify more.

class student {     private:         string id, fname, lname, level;         double gpa;     public:         student();         student(string id, string first, string last, double gpa, string grade);          string getid() const;         string getfirst() const;         string getlast() const;         string getlevel() const;         double getgpa() const;          void setid(string id);         void setfirst(string f1);         void setlast(string l1);         void setlevel(string lev);         void setgpa(double gpa1);          friend void sort(student studentlist[], int size);         friend ostream& operator <<(ostream& ost, student s1); };  int main() {     ifstream ins;     ofstream outs;     ins.open("input.dat");     outs.open("output.dat");      if(ins.fail())     {         cout << "file not found.";         exit(1);     }      if(outs.fail())     {         cout << "output file not opened.";         exit(1);     }       student a[200];     int x = 0;      while(!ins.eof())     {         string id, fnam, lnam, levl;         double point;         ins >> id >> fnam >> lnam >> point >> levl;          a[x].setid(id);         a[x].setfirst(fnam);         a[x].setlast(lnam);         a[x].setgpa(point);         a[x].setlevel(levl);           if(a[x].getid() == "")         {             break;         }          x += 1;     }      if(x == 0)     {         cout << "file empty" << endl;         return 0;     }      x = x +1;     a.sort(a, x);      int t=0;     while(t<x)     {         outs << a[t];         t += 1;     }       outs.close();     ins.close();     return 0; } 

get rid of a.. since sort free function, need just

sort(a, x); 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -