I am trying to define an unordered_set like this:
unordered_set<Point> m_Points;
When I compile it, I get the following error:
The C++ Standard doesn't provide a hash for this type.
Class Point
:
class Point{
private:
int x, y;
public:
Point(int a_x, int a_y)
: x(a_x), y(a_y)
{}
~Point(){}
int getX()const { return x; }
int getY()const { return y; }
bool operator == (const Point& rhs) const{
return x == rhs.x && y == rhs.y;
}
bool operator != (const Point& rhs) const{
return !(*this == rhs);
}
};
- How/where do I define a hash function for Point?
- What would be a good hash function for a 2D point?
std::pair<int, int>
... – Hellbender