The following C++ code gives me these errors when compiled:
covariant.cpp:32:22: error: invalid covariant return type for ‘virtual Q C::test()’
cova
You cannot do that. Overrides of virtual functions cannot change the prototype of the function, except very specific cases, such as the covariant return types.
Covariant return would be valid if you were to return in the virtual override a subclass of the type returned in the virtual base. But your Q and Q are unrelated by inheritance. The fact that B is a subclass of A does not make any difference here.