Thursday, 17 May 2018

Virtual Destructor

"Nice One Program"

//RULE
//RUlE:Virtual Destructor are used if want to delete the base class pointer to object of derived class
//if virtual dest not used normal destructor will be called and delte the base class part not the derived part

#include<iostream>

using namespace std;
class base
{
public:
base(){ }

virtual ~base(){
cout<<"Base destructor";
}

};

class dervd:public base
{
public:
  dervd(){ }
~dervd(){
cout<<"Derived Destructor\n";
}

};



int main()
{
base *ptr=new dervd();
delete ptr;


return 0;
}



No comments:

Post a Comment