#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
Just a precision: a way to implement virtual inheritance is to push (all) the virtual base classes at the end of the classes after all the own member fields declarations. Here should be the organization of class D and class B.
class D:
-----
pvmt for B, D (include shift to find A)
int b;
-----
pvmt for C (include shift to find A)
int c;
-----
int a;
-----
class B:
-----
pvmt for B (include shift to find A)
int b;
-----
int a;
-----
class C:
-----
pvmt for C (include shift to find A)
int c;
-----
int a;
-----
It is not new
that chooses the layout for void* rawObject= new (storage) B;
; It is the fact that you create a concrete B object. So the layout is the same than the one for contiguous
- the second one.