← Back to Inheritance
Question 453
Pure Virtual Function With a Definition
Pure Virtual Function With a Definition
A pure virtual function (= 0) makes its class abstract, but it may STILL have a body defined out of the class. Subclasses can reuse that shared implementation by calling it with the scope-resolution name. Create an abstract classEmployeewith a virtualstring describe() const = 0;that ALSO has an out-of-class definition returning "employee". GiveEmployeea virtual destructor. CreateManagerthat overridesdescribe()to returnEmployee::describe() + "/manager"by calling the base's provided body. Both a direct call and a call through anEmployee*print the output shown in Expected Output. Do NOT write a main function.
Expected Output:
employee/manager employee/manager
= newline. The output ends with a newline — print one after the last line.
Hints4 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.