我有一個類:C++ STL - 插入的自定義類作爲映射值
class Monster : public Player
{
public:
// Copy constructor - used for populating monster list in Game class
Monster(int newType)
{
type = newType;
canmove = true;
notforward = false;
}
int type;
bool operator==(const Monster& m) const {return type == m.type;}
bool operator!=(const Monster& m) const {return type != m.type;}
bool operator< (const Monster& m) const {return type < m.type;}
bool operator<=(const Monster& m) const {return type <= m.type;}
bool operator> (const Monster& m) const {return type > m.type;}
bool operator>=(const Monster& m) const {return type >= m.type;}
};
某些變量(如canmove和notforward)繼承。接着,在不同的類中創建地圖的怪物:
map<pair<int, int>, Monster> monsters; // Pair used for x and y coordinate
monsters.insert(make_pair(10, 10), Monster(10));
// Error - No instance of overloaded function
如何,我可以得到怪物實例到怪物的地圖?我添加了所有的運算符重載,以便能夠插入,但它不起作用!
這是爲什麼說「win32」?它與此無關。 – asveikau 2013-05-10 05:11:24
好點。編輯。 – 2013-05-10 05:26:50