← Back to Inheritance
Question 450
Diamond Problem With Virtual Inheritance
Diamond Problem With Virtual Inheritance
When two classes inherit from the same base and a fourth class inherits from both, you get the "diamond problem": two copies of the base and ambiguous member access.virtualinheritance fixes this by keeping a SINGLE shared base subobject.Person(already written) hasstring role() constreturning "person". CreateStudentandEmployeethat each inherit fromPersonusing VIRTUAL inheritance, andTeachingAssistantthat inherits from bothStudentandEmployee. Because of virtual inheritance,role()on aTeachingAssistantis unambiguous. The program prints the output shown in Expected Output. Do NOT write a main function.
Expected Output:
person= 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.