InterviewSolution
| 1. |
What Is Virtual Destructor? Why They Are Used? |
|
Answer» 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. 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. |
|