0

I have two structures. One for storing a point in 2D coordinate system:

struct Coordinate {
int x, y;
Coordinate() {};
Coordinate(int x, int y) : x(x), y(y) {};
} cr;

Another for storing the Coordinate and column number along with it.

struct BlobInformation {
Coordinate point;
int PixelValues[6];
int line;
int column;
char value;
} bi;

I'm trying to create a map which stores Coordinate as the Key and BlobInformation contents as the value.

When I try to insert the key, value pair it gives me the following error:

Severity    Code    Description Project File    Line    Suppression State
Error   C2678   binary '<': no operator found which takes a left-hand        operand of type 'const Coordinate' (or there is no acceptable conversion)  braille_obr c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstddef  240 
  • 1
    Please read your question and ask yourself "Could I answer that?" –  Mar 21 '16 at 19:00
  • `Coordinate` must implement an overload for `operator<()` or you need to specify an appropriate function for the [`Compare`](http://en.cppreference.com/w/cpp/container/map) template parameter. – πάντα ῥεῖ Mar 21 '16 at 19:00

1 Answers1

0

std::map is a sorted container, i.e. it sorts its keys with the < operator. Coordinate didn't implement one, that's why you are seeing this error. You can implement it (bool operator<(const Coordinate& rhs);, or use a std::unordered_map, which doesn't sort its keys.

Rakete1111
  • 47,013
  • 16
  • 123
  • 162