Consider the following code:
struct A { int m; };
struct B : A { void proc () { /* ... */ };
struct C : A { void proc () { /* ... */ };
A a;
B * b = (B *) &a;
C * c = (C *) &a;
b->proc ();
c->proc ();
Is that legal and well-defined?
Pro: A
is standard layout and B
and C
do not contain any data members.
Contra: a
is neither of B
nor of C
type.