2011年(100)
分类: C/C++
2011-04-21 17:24:07
#include class base { public: };virtual void display(){cout<<”\nBase”;} class derived : public base { public: };void display(){cout<<”\nDerived”;} void main() { base *ptr = new derived(); ptr->display();} |
#include class base { public: };~base() { } class derived : public base { public: };~derived() { } void main() { base *ptr = new derived(); // some code delete ptr; } |
#include class base { public: };virtual ~base(){} class derived : public base { public: };~derived() { } void main() { base *ptr = new derived(); // some code delete ptr; } |