

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I was going through great articles on C++ POD, Trivial and Standard Layout classes One property I haven't clearly understood about standard layout is the following:-

 A standard layout has no base classes of the same type as the first 
    non-static data member

So the following will not be a Standard Layout as it has the first member same as the base class

struct NonStandardLayout3 : StandardLayout1 {
    StandardLayout1 x; // first member cannot be of the same type as base

But performance-wise and property-wise how is the above struct any different than

struct StandardLayout5 : StandardLayout1 {
    int x;
    StandardLayout1 y; // can have members of base type if they're not the first   

which is the correction of the one above this.

share|improve this question
Related post. – legends2k Jan 8 '14 at 13:19
up vote 15 down vote accepted

The reason is that standard layout types effectively mandate the "empty base class optimization" where base classes with no data members take up no space and have the same address as the first data member (if any) of the derived class.

However, attempting doing this when the base class has the same type as the first data member violates the C++ memory model which requires that distinct objects of the same type must have distinct addresses.

From ISO/IEC 14882:2011 1.8 [intro.object]/6:

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

effectively mandating the empty base class, 9.2 [class.mem] /20:


It would be impossible for the following types (Type1 and Type2) to be layout-compatible (although they would otherwise be standard-layout classes) without this restriction.

struct S1 {};
struct S2 {};

struct Type1 : S1 {
    S1 s;
    int k;

struct Type2 : S1 {
    S2 s;
    int m;
share|improve this answer
This is exactly what the footnote for this rule at §9/7 says too: "[This rule] ensures that two subobjects that have the same class type and that belong to the same most derived object are not allocated at the same address" – James McNellis Jul 2 '12 at 20:24

Your Answer


