這一個類我只有protected
可變屬性,如int health
和int level
,但沒有方法。這是不好的做法嗎?我使用這個保存遊戲功能,它只需要使用變量,但不需要任何方法。該文件是這樣的:做一個在C++中只有可變屬性的類是不好的做法嗎?
Human.h:
// Human.h - Johnny P
#pragma once
namespace SharpEngine {
class Human {
protected:
std::string name;
int level;
int health;
int defense;
int strength;
int experience;
int money;
int inventory[10];
};
}
Human.cpp
// Human.cpp - Johnny P
#include <string>
#include "Human.h"
爲什麼不使用一個結構呢? –
@MaxE。爲什麼不使用它的類? – 2012-11-07 04:11:20
首字母縮略詞是POD =普通的舊數據,並且通常使用「struct」而不是「class」。 – dmckee