1
我想使用对我的实例的引用作为排序函数的参数。对std进行排序的功能:用&参数C++排序
我有vector<CMail> log
,类CMail
有我想要的功能。
而一个要排序log
所以我必须:
bool sortFunction(CMail a, CMail b){
return (a.CompareByTimeStamp(b) < 0) ? true : false;
}
然后
sort(log.begin(), log.end(), sortFunction);
它工作正常。但是,我可以将函数的参数作为参考吗?
bool sortFunction(CMail &a, CMail &b){
...
}
当我这样做,我的代码没有编译。
我该怎么做?
关闭我的头顶,我相信他们必须是'const CMail&'。编辑:[是](http://en.cppreference.com/w/cpp/algorithm/sort)。 – BoBTFish
另外,作为提问时的一般规则,您应该包含完整的编译器错误。 – BoBTFish