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...

when can we use virtual destructor?

Answer Posted / richa

It is used whenever a base class pointer is pointing to its
derived class.In such a case when a user tries to delete the
base class pointer then it results in deallocating the
memory occupied by the base class.Therefore instead the
derived class getting destroyed the base class does.Now as
the base class gets destroyed the base class pointer which
was pointing to its derived class hold no meaning as it is
already destroyed.
n such a case we should make the destructors of the base
class virtual so that whenever a delete is called on the
base class pointer then as the destructor is virtual the
compiler will call the destructor of the respective derived
class.Hence the scenario wont be breached when a base class
pointe points to derived class as it would help deleting the
respective derived class object.

Is This Answer Correct ?    86 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How are the features of c++ different from c?

1167


What is a loop? What are different types of loops in c++?

1177


Why isn't sizeof for a struct equal to the sum of sizeof of each member?

1059


What is the auto keyword good for in c++?

1262


What is the best way to take screenshots of a window with c++ in windows?

1094


Using a smart pointer can we iterate through a container?

1143


What do you mean by global variables?

1123


What are pointer-to-members? Explain.

1223


Explain mutable storage class specifier.

1128


What do you mean by persistent and non persistent objects?

1495


How do you flush std cout?

1148


How is modularity introduced in C++?

1283


What are the advantages of using typedef in a program?

1183


What is the main purpose of overloading operators?

1209


What is the most common mistake on c++ and oo projects?

1020