我有一个类: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