Daily bit(e) of C++ | Covariant return types
Daily bit(e) of C++ #465, Returning covariant return types from overriding virtual functions.
When working with virtual functions, we can encounter situations where we need to return a different type from an overriding function.
While this isn't possible in the general case, the types returned are allowed to be different if they are covariant.
Types returned by Base::fun() and Derived::fun() are covariant if:
both return a pointer or reference
the return type of Base::fun() is an unambiguous accessible base class of the type returned by Derived::fun()
the type returned by Derived::fun() isn't more cv-qualified
The prototypical use for covariant return types is a clone() function.