
Marco Servetto wrote:
The question is: C++ grants that A a; a.a2=8.8; assert(reinterpret_cast<B*>(&a)->b2==8.8);
Please note that my reply is based on the final public review document and thus not authoritative. Yes, it grants this, according to the rules of layout-compatible PODs.
it is even true for classes with inheritance?
No. The layout-compatibility rules only apply to PODs. POD-structs are defined by their lack of member pointer members, reference members, object members of non-POD type (recursively), user-defined copy assignment and user-defined destructor. But there is one more requirement: they must be aggregate classes. Aggregate classes are defined in 8.5.1: "An aggregate is an array or a class with no user-declared constructors, no private or protected non-static data members, no base classes, and no virtual functions." Sebastian Redl