Points我有一个像这样在 2D 空间中保存我的类:
class Point{
public:
Point(double a, double b){ x = a; y = b; }
//some additional information
private:
double x, y;
};
我喜欢将这些Points放在 astd::set但我不知道如何编写比较结构
struct cCompare{
bool operator()(const Point &p1, const Point &p2){
//what should I write here??
}
};
两点像p和q相等,如果(p_1,p_2) = (q_1,q_2)。我必须在Point课堂上存储一些额外的信息吗?每个索引或任何唯一编号之类的东西Point?并有这样的事情:
struct cCompare{
bool operator()(const Point &p1, const Point &p2){
return (p1.index < p2.index);
}
};