Reinterpreting a pointer to a derived class as a pointer to a base class gives undefined behaviour. This is highlighted by multiple inheritance: since there is more than one base class, and the two base subobjects must have different addresses, they can't both have the same address as the derived object. So the pointer returned by your create
function points to a Derived
, but not necessarily to the Interface
subobject. It could point to QObject
subobject, or to neither.
The best option is to return Derived*
or Interface*
from your function; if it must be void*
for some reason, then the only well-defined cast you can make is back to Derived*
, which can then be converted to Interface*
using standard conversions.
By using void*
you have thrown away all static and dynamic knowledge of the type; the only way to restore that information is to cast back to the correct type.