所以我正在创建一个类来定义 D&D 中的角色。我认为设置类的方式是公共成员在标题中定义,在 .cpp 中定义为私有成员,因此它们不会向外界透露,对吗?你怎么做到这一点?目前它看起来像这样,我确定这是错误的。
字符.h:
namespace d20 {
class character {
public:
character(void);
virtual ~character(void);
// get stats
int getStr();
int getDex();
int getCon();
int getIntl();
int getWis();
int getCha();
// get modifiers of the stats
int getStrMod();
int getDexMod();
int getConMod();
int getIntlMod();
int getWisMod();
int getChaMod();
};
};
字符.cpp:
namespace d20 {
class character {
private:
int str; // strength
int dex; // dexterity
int con; // constitution
int intl; // intelligence
int wis; // wisdom
int cha; // charisma
int hp; // hit points
int ac; // armor class
};
character::character(void) {
}
character::~character(void) {
}
}
是的,我知道有很多东西不见了,但这不是重点。Visual Studio 2010 在类视图中将其显示为 2 个名为 character 的类。我如何完成我的意图?这无关紧要,因为它是一项任务,并且所有代码无论如何都是可见的,但是对于未来,将私有成员排除在 .h 文件之外可能是明智之举吗?