I'm looking into the new, relaxed POD definition in C++11 (section 9.7)
A standard-layout class is a class that:
- has no non-static data members of type non-standard-layout class (or array of such types) or reference,
- has no virtual functions (10.3) and no virtual base classes (10.1),
- has the same access control (Clause 11) for all non-static data members,
- has no non-standard-layout base classes,
- either has no non-static data members in the most derived class and at most one base class with non-static data members, or has no base classes with non-static data members, and
- has no base classes of the same type as the first non-static data member.
I've highlighted the bits that surprised me.
What would go wrong if we tolerated data members with varying access controls?
What would go wrong if the first data member was also a base class? i.e.
struct Foo {};
struct Good : Foo {int x; Foo y;};
struct Bad : Foo {Foo y; int x;};
I admit it's a weird construction, but why should Bad
be prohibited but not Good
?
Finally, what would go wrong if more than one constituent class had data members?
struct
has always had all of its memberspublic
. C++11 has private now? – Neurogramprivate
members in astruct
in C++ (but not in C). The default ispublic
, though. – Electrodynamometer