2016-04-07 160 views
0

我只是一個初學者在c + +所以我只想做一個簡單的程序。 但我遇到了很多麻煩。 請告訴我如何解決這個錯誤,因爲我不太瞭解構造函數。我得到這個錯誤:隱式聲明的定義

#include <iostream> 
#include<windows.h> 
#include<fstream> 
using namespace std; 

int main() 
{ 
MessageBox(NULL,"YOU HAVE BEEN PROMOTED TO TEST THIS CONSOLE APP FOR FREE!!","PROMOTION!!",NULL); 
cout << "Hello world!............ first do you want this program to changeyour files to save progress??" << endl; 
int save; 
cout << "press 1 to allow press 2 to deny!!"<<endl; 
cin >> save; 
if(save == 1){ 

ofstream myfile; 
myfile.open ("data.txt"); 
} 
if(save == 2); 


cout<<"set up done!!!"<<endl; 


return 0; 
} 

,這是我的老闆

#ifndef BOSS_H 
#define BOSS_H 


class Boss 
{ 

    int boss_helth(){ 
     int boss_helth0 = 200; 
     return boss_helth(); 

    } 
void Punch(){ 



} 


}; 

類和最後我所有的播放器類

#ifndef PLAYER_H 
#define PLAYER_H 


class Player 
{ 

int Player_helth(){ 
Player_helth0 = 200; 
return player_helth0; 

} 
void patt(){ 
public: 

    int power_punch = - 20; 

} 





}; 

#endif // PLAYER_H 

我不知道爲什麼我收到此錯誤的。

` 
+0

嗯......有什麼錯誤? –

回答

0

看起來像錯誤是,當你試圖聲明變量Player_helth0時,你沒有指出類型。它應該是:

int Player_helth0 = 200; 

我也看到另一個(無關的)問題。在Boss_helth中,你的返回值應該是變量Boss_helth0,但是你要給該函數返回一個調用。

+0

@Aaron Hill,您的問題標題中的「隱式聲明」給了我一個提示,但是您應該真的將錯誤添加到問題的正文中,幷包含整個錯誤消息。這樣可以更容易理解問題並獲得幫助。 – Leon

+0

它讀取:隱式聲明的'Boss :: Boss()'的定義。 –

相關問題