CJCoding With Joseph
15free / daySign inCreate account

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. virtual inheritance fixes this by keeping a SINGLE shared base subobject.

Person (already written) has string role() const returning "person".

Create Student and Employee that each inherit from Person using VIRTUAL inheritance, and TeachingAssistant that inherits from both Student and Employee.

Because of virtual inheritance, role() on a TeachingAssistant is 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
Topics:
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.