简体   繁体   中英

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

I am trying to make a game in C++. My editor is Code::Blocks and my compiler is 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:

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. If any of the variables get to 0, the game ends:

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. 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.

You also have an issue with all of you if statements.

if (hunger = 0)

Will always be false as you are evaluating the result of setting hunger to 0 which is 0 . You need to change all of the uses = in your if's to == to do an equals comparison.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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