Here’s the problem code I’m attempting to compile:
bool TeamMatcher::simpleComparator(Student first, Student second){
return (first.numberOfHrsAvailable < second.numberOfHrsAvailable);
}
void TeamMatcher::sortRosters(){
sort(rosterExcellent.begin(), rosterExcellent.end(), simpleComparator);
sort(rosterGood.begin(), rosterGood.end(), simpleComparator);
sort(rosterOK.begin(), rosterOK.end(), simpleComparator);
sort(rosterPoor.begin(), rosterPoor.end(), simpleComparator);
sort(rosterNoSay.begin(), rosterNoSay.end(), simpleComparator);
}
Then here’s the error I’m getting:
TeamMatcher.C: In member function ‘void TeamMatcher::sortRosters()’:
TeamMatcher.C:51: error: no matching function for call to ‘sort(__gnu_cxx::__normal_iterator<Student*, std::vector<Student, std::allocator<Student> > >, __gnu_cxx::__normal_iterator<Student*, std::vector<Student, std::allocator<Student> > >, <unresolved overloaded function type>)’
/usr/include/c++/4.2.1/bits/stl_algo.h:2852: note: candidates are: void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Student*, std::vector<Student, std::allocator<Student> > >, _Compare = bool (TeamMatcher::*)(Student, Student)]
It repeats this error for the four remaining sorts. I don’t understand, I’m basically copy/pasting this solution from here: http://www.cplusplus.com/reference/algorithm/sort/
Any help would be greatly appreciated!
You need to declare your
simpleComparatoras astaticmethod, otherwise it won’t fit the type expected bystd::sort.To be perfectly correct, you should also then pass it as
TeamMatcher::simpleComparator, see here for details.