simpleinherit.cpp

来自「《24学时精通c++》的光盘内容」· C++ 代码 · 共 52 行

CPP
52
字号
 //Listing 16.1 Simple inheritance

 #include <iostream>

 

 enum BREED { YORKIE, CAIRN, DANDIE, SHETLAND, DOBERMAN, LAB };

 

 class Mammal

 {

 public:

     // constructors

     Mammal();

     ~Mammal();

 

     // accessors

     int GetAge() const;

     void SetAge(int);

     int GetWeight() const;

     void SetWeight();

 

     // Other methods

     void Speak();

     void Sleep();

 

 

 protected:

     int itsAge;

     int itsWeight;

 };

 

 class Dog : public Mammal

 {

 public:

     // Constructors

     Dog();

     ~Dog();

 

     // Accessors

     BREED GetBreed() const;

     void SetBreed(BREED);

 

     // Other methods

     // WagTail();

     // BegForFood();

 

 protected:

     BREED itsBreed;

 };

int main()

{

    return 0;

}



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?