No, this is not legal. You cannot replace the base subobject of an object.
C ++ 11 3.8 / 7 indicates that you can reuse object storage if
the original object was the most derived object (1.8) of type T, and the new object is the most derived object of type T (i.e. they are not subobjects of the base class ).
The object you replaced was a subobject of the base class, not the most derived object, so it is prohibited.
If you were to replace the whole object (i.e. call ~C , and then build a new C ), then this would be legal, but dangerous. If the designer abandoned, then the object will be destroyed a second time at the end of its service life. This will give undefined behavior.
source share