Explain the concept of covariant return types and show a use-case where it comes in handy!
Show answer and explanation
An overriding virtual function may return a pointer or reference to a more-derived class than the base function returns. This covariant return lets callers with derived static type receive the narrower result while base callers retain the base interface.
An overriding virtual function may return a pointer or reference to a more-derived class than the base function returns. This covariant return lets callers with derived static type receive the narrower result while base callers retain the base interface.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.