我想那種std::vector
使用algorithm::sort
,但我得到的運行時錯誤 Invalid operator <
。的std ::向量和算法::排序,有什麼不對下面的代碼
以下是我的代碼。
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());
運行時錯誤...?你有沒有注意到你的比較函數總是返回true? – 2011-06-06 19:49:03