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 does it mean when someone says I oop?

1061


What type of loop is a for loop?

1089


class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash

2280


Which is better struts or spring?

1050


What are different oops concepts?

1057


Which method cannot be overridden?

1089


What is the difference between a mixin and inheritance?

986


What is polymorphism programming?

1125


What is property in oops?

1059


Are polymorphisms mutations?

1157


i got a backdoor offer in process global,Bangalore..Can i work with it?

2841


design a c++ class for the chess board,provide a c++ class definition for such class(only class definition is required)

6676


What is multilevel inheritance explain with example?

1143


What is a null tree?

1133


What language is oop?

1007