soln9_2.cpp

来自「Wrox.Ivor.Hortons.Beginning.Visual.C.Plu」· C++ 代码 · 共 30 行

CPP
30 行
字号
/*
  It is reasonable to derive a CHawk class from CBird, but not COStrich because an ostrich cannot fly.
  A better hierarchy of classes to represent birds would allow flightless birds such as ostriches and penguins 
  to be represented by a separate class. The hierarchy below allows that.
*/

class CBird
{
protected:
  int wingSpan;
  int eggSize;
};

class CFlightlessBird: public CBird
{
};

class CFlyingBird: public CBird
{
protected:
  int airSpeed;
  int altitude;
public:
  virtual void fly( {altitude = 100;
};

/*
  Now CHawk can be derived from CFlyingBird and COstrich can be derived from CFlightlessBird
  and the both share the common base class CBird.
*/

⌨️ 快捷键说明

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