这是我的代码。我一直收到这个错误信息:
有人有什么想法如何解决吗?错误:在“) ”标记之前期望主表达式
void showInventory(player& obj) { // By Johnny :D
for(int i = 0; i < 20; i++) {
std::cout << "\nINVENTORY:\n" + obj.getItem(i);
i++;
std::cout << "\t\t\t" + obj.getItem(i) + "\n";
i++;
}
}
std::string toDo() //BY KEATON
{
std::string commands[5] = // This is the valid list of commands.
{"help", "inv"};
std::string ans;
std::cout << "\nWhat do you wish to do?\n>> ";
std::cin >> ans;
if(ans == commands[0]) {
helpMenu();
return NULL;
}
else if(ans == commands[1]) {
showInventory(player); // I get the error here.
return NULL;
}
}
showInventory(player& obj)
这一行告诉我们player
是一种类型,而不是一个对象。 - Luchian Grigoremain
中声明的,而不是在toDo
中。你需要将它作为参数传递。 - Luchian Grigoreplayer player;`
- Tux