我有一个存储在 STL Vector 中的非常基本的类。我正在尝试对该 vector 进行排序,但出现了神秘的 STL 错误。有人可以帮忙吗?
// Point.h
class Point {
public:
Point() : x(0), y(0) {}
Point( float x0, float y0 ) : x(x0), y(y0) {}
float x;
float y;
};
// Point.cpp, updated const as per given answers
bool operator< (const Point &p1,const Point &p2)
{
return p1.x < p2.x || (p1.x==p2.x && p1.y< p2.y);
}
同样,这个 Point 类存储在一个 vector 中并被排序:
std::vector<Point> tmp=N->points;
std::sort(tmp.begin(),tmp.end());
错误:
有人能指出我正确的方向吗?谢谢!
最佳答案
bool operator< (
<强> const
Point &p1,
<强> const
Point &p2 )
关于C++ 运算符重载 : STL sort on vector of my custom class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10308686/