我正在阅读有关C++ POD、Trivial 和标准布局类的精彩文章 我对标准布局还没有清楚了解的一个属性如下:-
A standard layout has no base classes of the same type as the first
non-static data member
因此以下将不是标准布局,因为它的第一个成员与基类相同
struct NonStandardLayout3 : StandardLayout1 {
StandardLayout1 x; // first member cannot be of the same type as base
};
但是在性能方面和属性方面,上述结构有何不同?
struct StandardLayout5 : StandardLayout1 {
int x;
StandardLayout1 y; // can have members of base type if they're not the first
};
这是对上面那个的更正。