我已经试过的指数来写这个代码:不能使用结构作为地图
#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;
}
事实上,这不是原来的代码,但简化了它的版本(我想使与OpenGL的俄罗斯方块游戏)。
无论如何,这个问题是一个语法错误,我说:“global_map [pos] =”home“;”。
我没有得到错误的原因,我张贴在这里,谁需要更多的细节:
invalid operands to binary expression (' position const' and 'position const')
你为什么在C++中使用'typedef'结构? –