Covariant Return Types With Clone
hardQuestion 452An overriding virtual function may return a pointer to a MORE derived type than the base declares. This is called a covariant return type and is commonly used for a clone() method.
Create a polymorphic base class Animal (virtual destructor; virtual string kind() const -> "animal"; virtual Animal* clone() const returning new Animal(*this)).
Create Dog that overrides kind() -> "dog" and overrides clone() to return Dog* (a covariant return) via new Dog(*this).
The runner clones a Dog both through an Animal* and directly, printing the copy's kind each time (see Expected Output).
Do NOT write a main function.
Expected output
dog dog
= newline. The output ends with a newline, so print one after the last line.
Hints2 available
Sign in to use hintsTopics
Inheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.