DreamsCoder.com

We Code your Dreams


home > Virtual Destructor in C++




Virtual Destructor in C++





#include iostream.h
class Base
{
   	public:
      	Base(){ cout<<"Constructing Base";}
      	
	
	virtual ~Base(){ cout<<"Destroying Base";}
};

class Derive: public Base
{
        public:
       	Derive(){ cout<<"Constructing Derive";}
       	
       	~Derive(){ cout<<"Destroying Derive";}
 };

void main()
{
    	Base *basePtr = new Derive();
        
        delete basePtr;
}
____________________________________
Output
____________________________________

Constructing Base  
Constructing Derive 
Destroying Derive
Destroying Base

Label - cpp





by - Chinmay Mahajan





Are you looking for something else?


Suggested Programs




Why C++ used in Clipper?


What does extern mean in a function declaration?


Friend Function Demonstration in C++


Vector Demonstration Program in C++