I have tried to write this code:
#include <iostream>
#include <map>
using namespace std;
typedef struct
{
int x;
int y;
}position;
int main(int argc, char** argv)
{
map<position, string> global_map;
position pos;
pos.x=5;
pos.y=10;
global_map[pos]="home";
return 0;
}
In truth this isn’t the original code, but a version simplified of it (I’ am trying to make a tetris game with OpenGL).
Anyway the problem is a syntax error on the line where I say: “global_map[pos]=”home”;”.
I don’t get the reason of the error, and I post it here for who needs more details:
invalid operands to binary expression (' position const' and 'position const')
The requirement for associative containers, which
std::mapis one of, is that there must be an ordering between the elements used as keys. By default, this isstd::lesswhich simply callsoperator <. So all you need to do to use yourstructas a key in astd::mapis implementoperator <for it.