What role does a virtual destructor play?
Show answer and explanation
A virtual base destructor ensures that deleting through a base pointer destroys the complete derived object. Without it, such deletion is undefined behavior; a non-polymorphic base can instead use a protected non-virtual destructor to forbid deletion through the base.
A virtual base destructor ensures that deleting through a base pointer destroys the complete derived object. Without it, such deletion is undefined behavior; a non-polymorphic base can instead use a protected non-virtual destructor to forbid deletion through the base.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.