为了研究C++的类的概念,写了个小程序来实际操作一下。 #include <iostream> using namespace std; class Miners { public: Miners(); ~Miners(); void DispInfo(Miners miner); void SetSpeed(int speed); void SetLength(int length); void SetHeight(int height); int GetSpeed(void); int GetLength(void); int GetHeight(void); private: int Speed; int Length; int Height; }; Miners::Miners() { Speed = 5; Length = 15; Height = 15; } Miners::~Miners() { } void Miners::DispInfo(Miners miner) { cout << "Speed: " << miner.Speed << endl; cout << "Length: " << miner.Length << endl; cout << "Height: " << miner.Height << endl; } void Miners::SetSpeed(int speed) { Speed = speed; } void Miners::SetLength(int length) { Length = length; } void Miners::SetHeight(int height) { Height = height; } int Miners::GetSpeed() { return Speed; } int Miners::GetLength() { return Length; } int Miners::GetHeight() { return Height; } int main(int argc , char *argv[]) { Miners miner01; miner01.DispInfo(miner01); miner01.SetSpeed(20); miner01.SetLength(18); miner01.SetHeight(10); miner01.DispInfo(miner01); return 0; }