class A { public: int a1; int b1; A() { cout<<"A's Constructor\n"; } virtual void foo() { cout<<"Base : foo\n"; } //~A() { cout<<"A's Destructor\n"; } virtual ~A() { cout<<"A's Destructor\n"; } }; class B : public A { public: B() { cout<<"B's Constructor\n"; } void foo() { cout<<"Dervied : foo\n"; } ~B() { cout<<"B's Destructor\n"; } }; int main() { A* a1 = new A(); cout<<"------------------Another------------------\n"; A* a2 = new B(); cout<<"------------------Another------------------\n"; B* b1 = new B(); cout<<"------------------D-->a1 Another------------------\n"; delete a1; cout<<"------------------D-->a2 Another------------------\n"; delete a2; cout<<"------------------D-->b1 Another------------------\n"; delete b1; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)