所以我有这个问题。我想从一个不同的类中获取一些变量,然后是主类,我知道隐藏你的数据是很好的,这样它就不会那么容易地改变并使用 getXXX 函数来访问它。我尝试使用private:和public:东西但是当我这样做时我得到一个错误说
错误:“私人”之前的预期不合格 ID
我得到了类 nr1# 称为对话框,带有变量的类称为种族(不像黑白那样)
无论如何我这样调用函数:(类对话框)
above this is all the #include stuff
dialog::dialog(int y)
{
race raceO;
switch(y)
{
case 1: cout << "choose a class \n1 ELF = " << raceO.getStats(1.1) << endl;
break:
}
这是比赛课
//我应该把私有:和公共:
include "race.h"
include <iostream>
include <string>
using namespace std;
race::race(){
}
int race::raceElf(){
return 0;
}
int attack = 5;
int defence = 3;
int stamina = 6;
int race::getStats(int x){
if(x == 11){
return attack;
}
return 0;
}