#include <stdio.h>class A{public: A() { printf("call A::A\n"); } ~A() { printf("call A::~A\n"); }};class B:public A{private: int *p;public: B() { p = new int[1000]; printf("call B::B\n"); } ~B() { if (p) { delete []p; } printf("call B::~B\n"); }};int main(int argc, int *argv[]){ A *z = new B; delete z; return 0;}
#include <stdio.h>class A{public: A() { printf("call A::A\n"); } virtual ~A() { printf("call A::~A\n"); }};class B:public A{private: int *p;public: B() { p = new int[1000]; printf("call B::B\n"); } ~B() { if (p) { delete []p; } printf("call B::~B\n"); }};int main(int argc, int *argv[]){ A *z = new B; delete z; return 0;}