Difficulty: Medium
Correct Answer: Base OK. Derived OK. Base DEL.
Explanation:
Introduction / Context:
This classic test examines destructor polymorphism. Deleting a derived object through a base pointer whose destructor is not virtual leads to only the base destructor being invoked, which is undefined behavior in standard C++ but typically manifests as the derived destructor not running (a resource leak risk).
Given Data / Assumptions:
Concept / Approach:
Construction of a derived object prints base message first, then derived message. On deletion through a base pointer without a virtual destructor, only the base destructor is called. The derived destructor is skipped, which is incorrect behavior but matches many legacy outputs.
Step-by-Step Solution:
Verification / Alternative check:
Making ~CuriousTabBase() virtual would produce: Base OK. Derived OK. Derived DEL. Base DEL.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting to declare virtual destructors in base classes intended for polymorphic deletion; overlooking UB concerns despite predictable prints in many toolchains.
Final Answer:
Base OK. Derived OK. Base DEL.
Discussion & Comments