C++错误:语句无法解析重载函数的地址
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;
}
}
在我告诉玩家代码的相同功能中,他们每回合在每个变量中损失一分:
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个语句,而不是一个输出语句。你需要
cout << "Your hunger is" << hunger << endl;
它把一切联系在一起。否则,它会尝试调用endl()
,但由于没有关联的流对象,因此无法调用。
你们所有人的if语句也有问题。
if (hunger = 0)
在评估将hunger
设置为0
(即0
)的结果时,将始终为false。您需要将if中的所有使用=
更改为==
,以便进行相等的比较。
相关文章:
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 可以打印矢量和矢量中的矢量的非重载C++函数
- 错误 没有与参数列表匹配的重载函数"getline"实例
- 使用模板重载函数
- C++线程中,没有重载函数接受 X 参数
- std::vector 没有重载函数的实例与参数列表匹配
- C++重载函数,一个采用基类的参数,另一个采用派生类的参数
- 错误:无法解析对重载函数的引用;你的意思是调用它吗?
- 对重载函数find_first_not_of的不明确调用
- 如何从重载解析中删除重载函数?
- CUDA:重载函数"isnan"的多个实例
- C++派生类重载函数(带有 std::function 参数)不可见
- 避免在人为的重载函数调用中拼写出类型
- C++:如何为多个重载函数保留通用代码路径?
- 什么时候可以使用常量装饰调用我的重载函数?
- 尝试使用谓词函数会导致错误:"std::sort"未找到匹配的重载函数
- std::调用,未找到匹配的重载函数
- 为什么在传递长整型时调用具有两个双精度类型的参数的重载函数?
- 为什么使用不匹配的参数调用重载函数仍然有效
- 如何通过签名作为模板参数来解决重载函数?