- //文件名:CHAPTER1-14.cpp
- #include <iostream.h>
- class A
- {
- public:
- virtual ~A() { cout<<"A::~A() Called.n"; }
- };
- class B : public A
- {
- public:
- B(int i) { buf = new char[i]; }
- virtual ~B()
- {
- delete [] buf;
- cout<<"B::~B() Called.n";
- }
- private:
- char * buf;
- };
- void fun(A *a)
- { delete a; }
- void main()
- {
- A *a = new B(15);
- fun(a);
- }