我想使用unordered_set带有自定义的struct。在我的情况下,自定义struct表示欧氏平面中的2D点。我知道应该定义一个哈希函数和比较器运算符,并且我已经做到了,如下面的代码所示:
struct Point {
int X;
int Y;
Point() : X(0), Y(0) {};
Point(const int& x, const int& y) : X(x), Y(y) {};
Point(const IPoint& other){
X = other.X;
Y = other.Y;
};
Point& operator=(const Point& other) {
X = other.X;
Y = other.Y;
return *this;
};
bool operator==(const Point& other) {
if (X == other.X && Y == other.Y)
return true;
return false;
};
bool operator<(const Point& other) {
if (X < other.X …Run Code Online (Sandbox Code Playgroud)