我只是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;
}
这是我的Boss课程
#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,但是您将返回对该函数的调用。