I have a map with a more or less custom Key-Type (Point2f
from OpenCV
) and thus need to write my own operator<
. Except, my operator<
doesn't get accepted.
Creation of the Map/Accessing an element by key:
using namespace cv;
void foo()
{
map<Point2f, double> properties;
properties[Point2f(0, 0)] = 0;
}
and this is my operator:
using namespace cv;
bool operator<(Point2f lhs, Point2f rhs)
{
return lhs.x == rhs.x ? lhs.y < rhs.y : lhs.x < rhs.x;
}
but when I try to set a value of the map using a key like above, my compiler gives me
/usr/include/c++/4.8/bits/stl_function.h|235|error: no match for ‘operator<’ (operand types are ‘const cv::Point_<float>’ and ‘const cv::Point_<float>’)|
(gcc, IDE Code::Blocks)
I already tried
- specifying the type exactly (
cv::Point_<float>
) - putting the operator directly above the function calling it
- using const, reference or const reference for the variables passed to the operator instead of values
Nothing worked, the error keeps coming. Why does it appear and what do I need to change to make it work?