区分接口继承和实现继承

纯虚函数能够定义函数体的应用:

 1 class Airplane{
 2 public:
 3     virtual void fly(const Airport& destination) = 0;
 4 };
 5 void Airplane::fly(const Airport& destination){ //纯虚函数的实现
 6     缺省行为
 7 }
 8 class mA :public Airplane{
 9 public:
10     virtual void fly(const Airport& destination){
11         Airplane::fly(destination);
12     }
13 };

以上,纯虚函数为派生的对象定义了接口,同时在派生类中可以显式的应用他们作为缺省的行为。

posted @ 2020-06-11 19:39  熊鑫xxx1x  阅读(191)  评论(0)    收藏  举报