下面 [class.derived]/7 中突出显示的表达式 "of the same type" 是什么意思?
What do they mean by the expressions "of the same type" highlighted below in [class.derived]/7?
[Note: A base class subobject might have a layout ([basic.stc])
different from the layout of a most derived object of the same
type. A base class subobject might have a polymorphic behavior
([class.cdtor]) different from the polymorphic behavior of a most
derived object of the same type. A base class subobject may be of
zero size ([class]); however, two subobjects that have the same class
type and that belong to the same most derived object must not be
allocated at the same address ([expr.eq]). — end note]
您是否正在寻找比显而易见的更深入的东西
class Animal {} // base
class Mammal : Animal {} // derived
class Dog : Mammal {} // most derived
动物、狗和哺乳动物都是动物类型。
考虑到多重继承的可能性(例如,您可以有另一个包含 AquaticOrganism 和 TerrestrialOrganism 的层次结构,并选择将 Dog 定义为(继承自)Mammal 和 TerrestrialOrganism),该段落指出 Dog 不能是假定布局为“Animal plus stuff”(可能是“TerrestrialOrganism plus...”)。
struct B { /* ... */ };
struct D : B { /* ... */ };
B b;
D d;
d
的基础 class 子对象 B
可能与相同类型(B
).例如,一个实现可以为 D
的成员重用 B
的尾部填充。
[Note: A base class subobject might have a layout ([basic.stc]) different from the layout of a most derived object of the same type. A base class subobject might have a polymorphic behavior ([class.cdtor]) different from the polymorphic behavior of a most derived object of the same type. A base class subobject may be of zero size ([class]); however, two subobjects that have the same class type and that belong to the same most derived object must not be allocated at the same address ([expr.eq]). — end note]
您是否正在寻找比显而易见的更深入的东西
class Animal {} // base
class Mammal : Animal {} // derived
class Dog : Mammal {} // most derived
动物、狗和哺乳动物都是动物类型。
考虑到多重继承的可能性(例如,您可以有另一个包含 AquaticOrganism 和 TerrestrialOrganism 的层次结构,并选择将 Dog 定义为(继承自)Mammal 和 TerrestrialOrganism),该段落指出 Dog 不能是假定布局为“Animal plus stuff”(可能是“TerrestrialOrganism plus...”)。
struct B { /* ... */ };
struct D : B { /* ... */ };
B b;
D d;
d
的基础 class 子对象 B
可能与相同类型(B
).例如,一个实现可以为 D
的成员重用 B
的尾部填充。