我已經試過的指數來寫這個代碼:不能使用結構作爲地圖
#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'結構? –