
#include <iostream>
using namespace std;
class A{
public:
virtual ~A( ){
cout<<"A::~A( ) called "<<endl; }
};
class B:public A{
char *buf;
public:
B(int i) { buf=new char[i]; }
virtual ~B( ){
delete []buf;
cout<<"B::~B( ) called"<<endl;
}
};
void fun(A *a) {
delete a;
}
int main( )
{ A *a=new B(10);
fun(a);
}
先析构派生类,在析构基类,如不是虚析构函数,仅会析构基类

517

被折叠的 条评论
为什么被折叠?



