+ 2
Benefits of virtual destructor in abstract classes?
I have an abstract class with a couple of pure virtual methods, so should i make the destructor virtual too? is there any benefit of doing that?
3 Réponses
+ 2
check out this-->http://www.geeksforgeeks.org/g-fact-37/
+ 2
thanks
0
Yes you should have a virtual destructor for a base class. The benefit of this is that it allows you delete a derived class object via a pointer to a base class object.
Vehicle *v = new Car();
delete v; // will call derived class destructor.
Failing to do this could result in a memory leak.