C++错误:语句无法解析重载函数的地址

C + + Error: statement cannot resolve address of overloaded function

本文关键字:重载 函数 地址 错误 语句 C++      更新时间:2023-10-16

我正在尝试用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中的所有使用=更改为==,以便进行相等的比较。