class Student{
public:
Student();
Student(string name, int score);
string getName();
int getScore();
void insert(string name, int score);
friend ostream& operator<<(ostream& os, const Student& student){
os << "Name: "<<student.name<<",Score:"<<student.score<<endl;
return os;
}
private:
string name;
int score;
};
string Student::getName(){
return name;
}
int Student::getScore(){
return score;
}
I define above class
and main function I define a comparison function
int compStudent(const Student &student1, const Student &student2){
int score1 = student1.getScore();
int score2 = student2.getScore();
if(score1 == score2) return 0;
if(score1<score2) return -1;
return 1;
}
Then the error is said this argument is const but function is not const.
Then I delete the const, it works why?