Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Explain the need for "Virtual Destructor"?

Answer Posted / p govind rao

A destructor can be declare virtual. virtual destructor is
mainly useful during inheritance.

class base
{
public:
base(){}
virtual ~base(){}
};

class derv
{ char *p;
public :
derv(){ptr=nes char[2];}
~derv(){delete ptr;}

} ;

main()
{
base *baseptr=new derv();
delete baseptr;
}

If base class, and derived class, and a dynamically
allocated object of type derived is deleted via a pointer
of type base, then derived's destructor will not be invoked
unless base's destructor is virtual.

base *baseptr = new derv();
delete baseptr; // won't invoke B's destructor unless A's
destructor is virtual

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Define anonymous class.

1038


What is the use of endl?

933


Difference between overloading vs. Overriding

1040


What does override mean in c++?

1033


What is pointer to member?

1032


What is the difference between map and hashmap in c++?

1057


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

2545


What is microsoft c++ redistributable?

1040


What are the three forms of cin.get() and what are their differences?

1167


Write a program to find the Fibonacci series recursively.

1038


What are the various storage classes in C++?

1106


What is an operator function? Describe the function of an operator function?

1084


What is c++ programming language?

1064


What are enumerations?

1064


Can member data be public?

1009