#include
using namespace std;
class base
{
public:
base();
~base();
};
base::base()
{
cout<<"base construct"<}
base::~base()
{
cout<<"base deconstruct"<}
class child:public base
{
public:
child();
~child();
};
child::child()
{
cout<<"child construct"<}
child::~child()
{
cout<<"child deconstruct"<}
void main()
{
base *ptr=new child();
delete ptr;
ptr=NULL;
}
结果:
base construct
child construct
base deconstruct
child deconstruct
如果没有virtual的话,结果是:
base construct
child construct
base deconstruct
阅读(598) | 评论(0) | 转发(0) |