Explain the concept of covariant return types and show a use-case where it comes in handy!
Show answer and explanation
Covariant returns allow an override to narrow a returned class pointer or reference to a derived type. The rule applies only to compatible pointer/reference class returns, not arbitrary values or smart pointers.
Covariant returns allow an override to narrow a returned class pointer or reference to a derived type. The rule applies only to compatible pointer/reference class returns, not arbitrary values or smart pointers.
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.