QQ1. What is a Virtual Destructor? What are its advantages? Explain with examples.
- A virtual destructor ensures correct destructor invocation in polymorphic hierarchies.
- It prevents memory and resource leaks when deleting derived objects via base pointers.
- Without it, only the base class destructor is called, skipping derived class cleanup.
- The `virtual` keyword enables dynamic dispatch of destructors via the v-table.
Answer: In C++ programming, a destructor is a special member function of a class that is automatically invoked when an object of that class goes out of scope or is explicitly deleted using the `delete` operator. Its primary purpose is to deallocate any resources (such as dynamically allocated memory, file handles, or network connections) that the object might have acquired during its lifetime, thereby preventing resource leaks. However, in the context of inheritance and polymorphism, a standard (non-vi...