は、私がコンパイルしようとしてる問題のコードです:このC++ Vector Sortingエラーをどのように克服できますか?ここ
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);
}
次に、ここで私は取得していますエラー:
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)]
それは、残りの4つの種類のために、このエラーが繰り返されます。私は理解していません。基本的には、ここからこのソリューションをコピーして貼り付けています:http://www.cplusplus.com/reference/algorithm/sort/
ご協力いただけると助かります。
'namespace std;'を使用して名前空間の指示文をファイルに追加しましたか? 'std'名前空間を' std :: sort'としてアルゴリズムの名前を品質化する必要がない場合は、ファイルに追加しましたか? –
少なくとも私の.hファイルで、この.Cファイルにインポートしました。それでもいいよね? –
@Als - コンパイラの出力から、すでに 'std :: sort'が候補になっていることがわかります。これは問題ではないことを意味しています。 – tzaman