I stumbled upon a problem I cannot solve regarding maps. As we know, maps require the two type of variables it is gonna handle i.e. map, but what about custom types?
Let's say I have an object called 'Point' which consists in two variables, x and y. Is it feasible to declare a map like: map?. Please look at the code below
class Point
{
public:
double x;
double y;
Point(double x, double y)
{
this->x=x;
this->y=y;
}
};
int main(int argc, const char * argv[])
{
map<Point,int> myMap;
Point p1(0,0);
myMap[p1]=1;
}
I'm receiving a compilation error: 'Invalid operands to binary expression ('const Point' and 'const Point').
Does anyone know why this is happening and how can I solve it? Any help would be really appreciated :).
Cheers!