我正在尝试使用矢量实现创建库存系统,但我似乎遇到了一些麻烦。我在使用我制作的结构时遇到了问题。注意:这实际上不在游戏代码中,这是我用来测试我对向量和结构的知识的单独解决方案!
struct aItem
{
string itemName;
int damage;
};
int main()
{
aItem healingPotion;
healingPotion.itemName = "Healing Potion";
healingPotion.damage= 6;
aItem fireballPotion;
fireballPotion.itemName = "Potion of Fiery Balls";
fireballPotion.damage = -2;
vector<aItem> inventory;
inventory.push_back(healingPotion);
inventory.push_back(healingPotion);
inventory.push_back(healingPotion);
inventory.push_back(fireballPotion);
if(find(inventory.begin(), inventory.end(), fireballPotion) != inventory.end())
{
cout << "Found";
}
system("PAUSE");
return 0;
}
前面的代码给了我以下错误:
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(3186): error C2678: binary '==' : no operator found which take a left-hand operand of type 'aItem' (或者没有可接受的转换)
错误还有更多,如果您需要它,请告诉我。我敢打赌这是一件小而愚蠢的事情,但我已经敲了两个多小时。提前致谢!