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

前端 未结 4 725
一个人的身影
一个人的身影 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:25

    In the final version of the C++11 standard, that paragraph was revised to read:

    Unless an object is a bit-field or a base class subobject of zero size, the address of that object is the address of the first byte it occupies. Two objects that are not bit-fields may have the same address if one is a subobject of the other or if at least one is a base class subobject of zero size and they are of different types; otherwise, they shall have distinct addresses.

    Although I am not sure I understand what this has to do with the sizes of the objects.

提交回复
热议问题