我正在尝试按降序对包含 struct
项目的列表(类的一部分)进行排序,但它无法编译:
错误:’__last - __first’ 中的 ‘operator-’ 不匹配
sort(Result.poly.begin(), Result.poly.end(), SortDescending());
这是 SortDescending
:
struct SortDescending
{
bool operator()(const term& t1, const term& t2)
{
return t2.pow < t1.pow;
}
};
谁能告诉我怎么了?
原文由 Vlad 发布,翻译遵循 CC BY-SA 4.0 许可协议
标准算法
std::sort
需要随机访问迭代器,而std::list<>::iterator
则不需要(列表迭代器是双向迭代器)。您应该使用
std::list<>::sort
成员函数。