刷题时遇到了奇怪的错误
题目来至https://www.我的代码:
程序代码:
#include<iostream> #include<vector> #include<algorithm> #include<string.h> using namespace std; typedef struct report Report; struct report { char Number[9]; int score1; int score2; }; class Solution{ public: bool cmp(Report a,Report b) { if(a.score1+a.score2 > b.score1+b.score2) return true; else if(a.score1+a.score2 == b.score1+b.score2) { if(a.score1 > b.score1) return true; if(a.score1 == b.score1) return strcmp(a.Number,b.Number) < 0 ? true : false; } return false; } void scoreSort(){ vector<vector<Report> > student; student.resize(4); int n,L,H; cin>>n>>L>>H; int count=0; for(int i=0;i<n;i++){ Report stu; cin>>stu.Number>>stu.score1>>stu.score2; if(stu.score1<L || stu.score2<L) continue; count++; if(stu.score1>=H && stu.score2>=H) student[0].push_back(stu); else if(stu.score1>=H && stu.score2<H) student[1].push_back(stu); else if(stu.score1<H && stu.score1>=stu.score2) student[2].push_back(stu); else student[3].push_back(stu); } for(int i=0;i<4;i++){ sort(student[i].begin(),student[i].end(),cmp); } for(int i=0;i<4;i++){ vector<Report>::iterator it; for(it=student[i].begin();it != student[i].end();it++) cout<<it->Number<<" "<<it->score1<<" "<<it->score2<<endl; } } }; int main(){ Solution a; a.scoreSort(); return 0; }
错误:
error: must use '.*' or '->*' to call pointer-to-member function in '((__gnu_cxx::__ops::_Iter_comp_iter<bool (Solution::*)(report, report)>*)this)->__gnu_cxx::__ops::_Iter_comp_iter<bool (Solution::*)(report, report)>::_M_comp (...)', e.g. '(... ->* ((__gnu_cxx::__ops::_Iter_comp_iter<bool (Solution::*)(report, report)>*)this)->__gnu_cxx::__ops::_Iter_comp_iter<bool (Solution::*)(report, report)>::_M_comp) (...)'|
看提示,大概是sort()的用法错了,搞不懂,不能这样调用吗?
[此贴子已经被作者于2018-3-16 12:19编辑过]