Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++empty base optimizationSingle-choice MCQ

A class derives from an empty base, but that base has a virtual function. The derived class is otherwise just an `int`. Why does empty base optimization fail to collapse this base to zero bytes?

struct Base { virtual void f() {} }; // no data members struct Derived : Base { int x; };