Multiple ChoiceBeginner 45s
Why a base class needs a virtual destructor
Why must a polymorphic base class have a virtual destructor if derived objects are deleted through base pointers?
Options
- 1Otherwise the base destructor runs twice, once for the base sub-object and once for the derived
- 2Because a virtual destructor is required by the vtable layout of every polymorphic class
- 3Otherwise deleting through the base pointer is undefined behavior and the derived destructor may not run
- 4Because a non-virtual destructor simply cannot be called on a base object through a pointer
Think you can answer under pressure?
Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.