#include "stdafx.h"
#include<iostream>
using namespace std;
class A{
public:
virtual void show(){
cout<<"in classA"<<endl;
}
virtual ~A(){}
};
class B{
public:
virtual void show(){
cout<<"in classB"<<endl;
}
virtual ~B(){}
};
class MidA:public A{
public:
virtual void realshowA() = 0;
virtual void show(){
realshowA();
}
// virtual ~MidA(){}
};
class MidB:public B{
public:
virtual void realshowB() = 0;
virtual void show(){
realshowB();
}
// virtual ~MidB(){}
};
class Derive :public MidA,public MidB{
public:
void realshowA(){
cout<<"realshow in classA"<<endl;
}
void realshowB(){
cout<<"realshow in classB"<<endl;
}
// virtual ~Derive(){}
};
int main(int argc,char * argv){
A *pa= new Derive;
B *pb= new Derive;
pa->show();
pb->show();
delete pa;
delete pb;
return 0;
}
只要基类声明为析构函数,派生类的所有析构函数自然也为虚函数。参考effective C++ 条款07