The C-style cast is unsafe, because it is not guaranteed that the COne
object and its BaseOne
subobject have the same memory address (it is guaranteed if COne
is a standard-layout class (9p7), but that generally precludes polymorphism).
The compiler needs COne
to be complete to perform the cast (3.2p5) because COne
could use virtual or multiple inheritance, and in general because polymorphic classes are not required to have a simple memory layout.
struct COne: BaseZero, BaseOne { ... };
struct COne: virtual BaseOne { ... };
You're going to have to either move the cast to a point in a source file where the definition of COne
is available, or write your own casting function BaseOne *to_base(COne *)
with an implementation at a point in a source file where the definition of COne
is available.