Programming with Passion

Make the best out of everything.

Friday, 8 April 2016

What is virtual destructors? Why they are used?

What is virtual destructors? Why they are used?
[This c++ interview question is in a way related to polymorphism.]
Virtual destructors are used for the same purpose as virtual functions. When you remove an object of subclass, which is referenced by a parent class pointer, only destructor of base class will get executed. But if the destructor is defined using virtual keyword, both the destructors [ of parent and sub class ] will get invoked.

No comments:

Post a Comment