CPlusPlusThings/practical_exercises/10_day_practice/day6/虚函数/虚析构函数.cpp
Light-City a4d828bb4c update
2020-04-06 00:57:02 +08:00

23 lines
340 B
C++

#include <iostream>
using namespace std;
class A{
public:
virtual ~A(){ cout<<"call A::~A()"<<endl; }
};
class B:public A{
char *buf;
public:
B(int i){buf=new char[i];}
~B(){
delete [] buf;
cout<<"call B::~()"<<endl;
}
};
int main(){
A* a=new B(10);
delete a;
system("pause");
return 0;
}