I am trying sort std::vector using algorithm::sort , But I am getting runtime error
Invalid operator <.
Following is my code.
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;
}
};
Here is now I am calling it after populating the values.
std::sort( posVector.begin(), posVector.end(), compareX());
Your comparison function always returns true!