C++语言程序设计

我们再举个例子说明：

| 例11-25

#include "iostream.h"
class A
{
public:
int *a;
A() { a=new(int); }
virtual void func1(){}
virtual void func2(){}
~A() {delete a; cout<<"delete a"<<endl; }
};

class B:public A
{
public:
int *b;
B() {b=new(int); }
virtual void func1(){}
virtual void func2(){}
virtual void func3(){}
~B() { delete b; cout<<"delete b"<<endl; }
};

void main()
{
A *pb=new B();
delete pb;
}

程序运行结果：
delete a