I have a circle defined like so:
class Circle {
public:
int x;
int y;
int r;
Circle() : x(0), y(0), r(0) {}
Circle(int x, int y, int r) {
this->x = x;
this->y = y;
this->r = r;
}
double area() {
return PI * pow(r, 2);
}
};
I want to be able to add it to a set, based on the hash of its center (x
and y
)
What's the correct and idiomatic way of doing this in C++ 11?
My question is two-fold
(1) Is there a way I can ask C++ to hash it for me? In Kotlin, there is the notion of a dataclass which automatically hashes the class attributes. I am looking for something similar.
(2) If not, how do I hash it myself, and relatedly - what are operators I need to overload?