Thursday, November 18, 2010

Empty Base Class Optimization (EBCO)

Given the following classes:

   class Base
   { }; 

   class Derived : public Base 
   { }; 
  

If your compile implements the Empty Base Class Optimization (EBCO) and the sizeof(Base) == 1, then the sizeof(Derived) is 1.
Since there is only one subobject, the object and the subobject can share the same address.

Reference: C++ Templates: The complete guide by David Vandevoorde and Nicolai M. Josuttis. Addison-Wesley, 2003, pp. 289-292.

No comments:

Post a Comment