我正在尝试排序 std::vector
使用 algorithm::sort
, 但我收到运行时错误
Invalid operator <
.
以下是我的代码。
struct Point {
double x_cord;
double y_cord;
int id;
Point(int d, double x, double y) {
x_cord = x;
y_cord = y;
id = d;
}
};
struct compareX {
bool operator ()(Point * left, Point* right) const {
if (left->x_cord < right->x_cord)
return true;
return true;
}
};
struct compareY {
bool operator ()(Point * left, Point* right) const {
if (left->y_cord <= right->y_cord) return true;
return true;
}
};
现在我在填充值后调用它。
std::sort( posVector.begin(), posVector.end(), compareX());
最佳答案
你的比较函数总是返回真!
关于c++ - std::vector 和 algorithm::sort ,以下代码有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6257166/