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

Why and when is a virtual destructor needed?

Answer Posted / uma sankar pradhan

A virtual destructor is needed when we are deleting a
object of derived class using a base class pointer.
i.e.,
base *b=new derived;
delete(b);
Let's say,we have allocated memory dynamically in derived
class constructor to a pointer data member and we
deallocated it in the destructor to avoid memory leakage
When the object is deleted through base class pointer,
only the base class destructor is invoked.consequently,the
dynamically allocated space remains unreleased.so it leads
to memory leak

Is This Answer Correct ?    34 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a null tree?

1193


What is the difference between procedural programming and oops?

1211


What is polymorphism in oops with example?

1107


What is Difeerence between List obj=new ArrayList(); and ArrayList obj=new ArrayList()?

2596


Can private class be inherited?

1226


Can we create object of interface?

1176


What is class and example?

1266


State what is encapsulation and friend function?

1344


How Do you Code Composition and Aggregation in C++ ?

25615


Why do we use class in oops?

1024


What is inheritance write a program to show use of inheritance?

1204


Can a destructor be called directly?

1138


What do you mean by variable?

1096


Why we use classes in oop?

1098


what's the basic's in dot net

2235