The definitions of three classes are as follows:
class A { }; class B { A a; }; class C : public A { B b; };
According to the definition of a standard-layout class in C++11:
- 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
Classes A and B are clearly standard-layout classes. The issue arises with class C, which doesn't appear to violate any of the standard-layout class definitions, yet it is still defined as a non-standard-layout class. Does class C violate any specific rule?
I used the Clang compiler for testing.
Aucun commentaire:
Enregistrer un commentaire