[英]C + + Error: statement cannot resolve address of overloaded function
我正在尝试用C ++制作游戏。 我的编辑器是Code :: Blocks,我的编译器是MinGW。 该游戏是基于文本的生存游戏,具有饥饿,口渴,温暖和选择等变量。 当我尝试告诉玩家饥饿,口渴和温暖的价值观时,这给了我这个问题的标题所指出的错误。 我是一个相对较新的程序员,但我了解基本知识。 我现在将打印我使用的代码:
cout<< "Your hunger is"; hunger; endl;
cout<< "Your warmth is"; warmth; endl;
cout<< "Your thirst is"; thirst; endl;
这是变量被更改的地方(这是一个示例):
int wood()
{
cout<< "You have chosen find firewood!"<< endl;
if ((rand() % 2) == 2){
cout<< "You found firewood!"<<endl;
warmth = warmth + 1;
}
else{
cout<< "You could not find any firewood"<< endl;
}
}
在我告诉玩家代码的相同功能中,他们应该每回合在每个变量中损失1分:
warmth = warmth - 1;
hunger = hunger - 1;
thirst = thirst - 1;
该代码长度超过100行,因此除非有要求,否则我不会粘贴整个代码。 如果任何变量变为0,则游戏结束:
if (hunger = 0){
cout<< "You starved!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
if (thirst = 0){
cout<< "You became dehydrated!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
if (warmth = 0){
cout<< "You froze!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
它应该是:
cout<< "Your hunger is" << hunger << endl;
等等
您的代码中有几次错字。 当你做
cout<< "Your hunger is"; hunger; endl;
您有3条语句,而不是1条输出语句。 你想拥有
cout << "Your hunger is" << hunger << endl;
哪些将它们链接在一起。 否则,它将尝试调用endl()
但由于没有关联的流对象,因此无法调用。
您所有人的if语句也有问题。
if (hunger = 0)
在评估将hunger
设置为0
即0
的结果时,它将始终为false。 您需要将if中的所有用法=
更改为==
以进行均等比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.