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

时间:2016-04-05 18:54:33

标签: c++ function variables

我正在尝试用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;
}

2 个答案:

答案 0 :(得分:1)

应该是:

cout<< "Your hunger is" << hunger <<  endl;

等等

答案 1 :(得分:1)

你的代码中有一些拼写错误。当你这样做

cout<< "Your hunger is"; hunger;  endl;

您有3个语句而不是一个输出语句。你有

cout << "Your hunger is" << hunger << endl;

将它们连在一起。否则它会尝试调用endl(),但它不能,因为没有关联的流对象。

如果你发表声明,你也会遇到问题。

if (hunger = 0)

在评估将hunger设置为0 0的结果时,将始终为假。您需要将if中的所有用途=更改为==才能进行等效比较。