我试图找到存储在向量中的最大学生分数。 这是我的代码。 SL是学生对象的向量。
class Student{
public:
int returnScore(){return score;}
private:
int score;
};
class StudentList{
public:
vector<Student>sl;
bool compare( Student& s1,Student &s2)
{
return (s1.returnScore()<s2.returnScore());
}
void highest_score()
{
auto max_score = max_element(sl.begin(),sl.end(),compare);
if(max_score == sl.end()){}
//cout<<"Container empty.\n";
else{}
// cout<<*max_score;
}
};
int main()
{
StudentList l;
l.highest_score();
}
编译器将我带到C ++官方库并给出了错误。
error: must use '.*' or '->*' to call pointer-to-member function in '((__gnu_cxx::__ops::_Iter_comp_iter<bool (StudentList::*)(Student&,Student&)>*)this)->__gnu_cxx::__ops::_Iter_comp_iter<bool (StudentList::*)(Student&,Student&)>::_M_comp (...)',e.g. '(... ->* ((__gnu_cxx::__ops::_Iter_comp_iter<bool (StudentList::*)(Student&,Student&)>::_M_comp) (...)'|