Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++multiple and virtual inheritance layoutSingle-choice MCQ

Calling delete on a base pointer to a derived object created with multiple inheritance can corrupt the heap unless the destructor is virtual. Beyond calling the wrong destructor, what specific layout problem does a non-virtual destructor cause here for a B2* (the non-first base)?

struct B1 { int a; ~B1(){} }; struct B2 { int b; ~B2(){} }; // non-virtual dtor struct D : B1, B2 { int c; }; B2* p = new D(); delete p; // why is this dangerous beyond wrong dtor?