Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:14:03+00:00 2026-06-06T22:14:03+00:00

I was going through great articles on C++ POD, Trivial and Standard Layout classes

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:14:04+00:00Added an answer on June 6, 2026 at 10:14 pm

    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:

    A pointer to a standard-layout struct object, suitably converted using a reinterpret_cast, points to its
    initial member (or if that member is a bit-field, then to the unit in which it resides) and vice versa.

    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;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any help or pointers would be great on this, I'm going through the ASP.NET
I'm going through Michael Hartl's Ruby on Rails 3.2 Tutorial and I'm confused about
After going through the Appendix A, C# Coding Style Conventions of the great book
I am going through Write Yourself a Scheme in Haskell . Its a great
Just found out about Caliper, and going through the documentation - it looks like
Going through happstack-lite tutorial : we build functions that have return type of ServerPart
Going through some of my older Delphi projects and upgrading them to D2009, as
Going through Javascript documentation, I found the following two functions on a Javascript object
Going through the microsoft authentication tutorial listed here they have you create a master
Going through some documentation on modifying CGImageRef data, I came across a strange example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.