CJCoding With Joseph

Polymorphism Through a Base Reference

Virtual 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:
Hello

Do NOT write a main function.

Expected Output:

Hello
Topics:
Inheritance
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.