简体   繁体   English

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

[英]C + + Error: statement cannot resolve address of overloaded function

I am trying to make a game in C++. 我正在尝试用C ++制作游戏。 My editor is Code::Blocks and my compiler is MinGW. 我的编辑器是Code :: Blocks,我的编译器是MinGW。 The game is a text-based survival game with the variables hunger, thirst, warmth, and choice. 该游戏是基于文本的生存游戏,具有饥饿,口渴,温暖和选择等变量。 When i try to tell the player the values of hunger, thirst, and warmth, it gives me the error that the title of this question states. 当我尝试告诉玩家饥饿,口渴和温暖的价值观时,这给了我这个问题的标题所指出的错误。 I am a relatively new programmer, but i understand the basics. 我是一个相对较新的程序员,但我了解基本知识。 I will now print the code i used: 我现在将打印我使用的代码:

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

This is where the variables get changed (this is one example): 这是变量被更改的地方(这是一个示例):

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;
}
}

In the same function that i tell the player the code, they are supposed to lose one point in each variable per turn: 在我告诉玩家代码的相同功能中,他们应该每回合在每个变量中损失1分:

warmth = warmth - 1;
hunger = hunger - 1;
thirst = thirst - 1;

The code is over 100 lines long, so i wont paste the entirety of the code unless asked. 该代码长度超过100行,因此除非有要求,否则我不会粘贴整个代码。 If any of the variables get to 0, the game ends: 如果任何变量变为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;
}

It should be: 它应该是:

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

and so on 等等

You have a couple typos in you code. 您的代码中有几次错字。 When you do 当你做

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

You have 3 statements instead of one output statement. 您有3条语句,而不是1条输出语句。 You nned to have 你想拥有

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

Which chains it all together. 哪些将它们链接在一起。 Otherwise it trys to call endl() but it can't since there is no associated stream object. 否则,它将尝试调用endl()但由于没有关联的流对象,因此无法调用。

You also have an issue with all of you if statements. 您所有人的if语句也有问题。

if (hunger = 0)

Will always be false as you are evaluating the result of setting hunger to 0 which is 0 . 在评估将hunger设置为00的结果时,它将始终为false。 You need to change all of the uses = in your if's to == to do an equals comparison. 您需要将if中的所有用法=更改为==以进行均等比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM