Polymorphism Through a Base Reference
easyQuestion 435Virtual dispatch works through base REFERENCES, not only pointers.
Base class Speaker has a virtual method string speak() const returning "...".
Create a derived class Human that overrides speak() to return "Hello".
The runner binds a Speaker& reference to a Human and calls speak() through it. Because speak() is virtual, the program prints the output shown in Expected Output.
Do NOT write a main function.
Expected output
Hello= 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.