Should an empty base class affect the layout of the derived class?

前端 未结 4 737
一个人的身影
一个人的身影 2021-01-18 19:42

The C++ standard (quoting from draft n3242) says the following about subobjects [intro.object]:

Unless an object is a bit-field or a base class subobj

4条回答
  •  终归单人心
    2021-01-18 20:08

    This is implementation-dependent.

    The standard explicitly allows the Empty Base Optimization, but does not require it. In fact, the standard doesn't require much of anything about the layout of classes in memory, only that certain classes will be layout-compatible with each other (but not what the common layout is). Order of members is also specified (when there is no intervening accessibility specifier), but padding, headers, footers, and all manner of weirder stuff is allowed.

提交回复
热议问题