#include
#include
struct A { int a; };
struct B : virtual A { int b; };
struct C : virtual A { int c; };
struct D : B,C { int d; };
in
There is no option to create what you call a "separate" layout, other than creating a derived type, and fishing B
out of it.
"Layout of B
as portion of its derived class" is not the same as "Layout of B
". Placement new
and regular new
use the layout based on the type itself, with is the default, stand-alone layout.
Where is the guarantee that the layout created by new fits into a buffer of size
sizeof(B)
?
sizeof(B)
returns the size of B
itself, not B
-as-part-of-some-other-class. That is all the space needed to store a stand-alone B
, regardless of the way that you allocate memory for it.