โ 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: employee/manager employee/manager Do NOT write a main function.
Expected Output:
employee/manager employee/manager
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.