#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
Where is the guarantee that the layout created by new fits into a buffer of size sizeof(B) and with offset zero
From the the type being named in new
as its argument being B
. A B
is being made, not an D
. The type B
"knows nothing" about D
. The declaration of D
has no influence on B
; the B
declaration can be put into translation units in which D
doesn't appear, yet everywhere in the program there will be agreement about the size of B
and is layout, regardless of whether D
is also known in those places or not.
A C++ object of type T
has a size sizeof T
. This means that it fits into sizeof T
bytes; it cannot be the case that (sizeof T) + k
bytes are required for its representation, where k > 0
.