簡體   English   中英

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

在我告訴玩家代碼的相同功能中,他們應該每回合在每個變量中損失1分:

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條語句,而不是1條輸出語句。 你想擁有

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

哪些將它們鏈接在一起。 否則,它將嘗試調用endl()但由於沒有關聯的流對象,因此無法調用。

您所有人的if語句也有問題。

if (hunger = 0)

在評估將hunger設置為00的結果時,它將始終為false。 您需要將if中的所有用法=更改為==以進行均等比較。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM