Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Multiple Inheritance

Python

Some useful resources to accompany this example:

Output:

C++

To accompany this example, you may wish to read:

C++ doesn’t, by default, use a resolution order to resolve the diamond problem.

Output:

This makes referring to inherited methods from A in D problematic, as it is ambiguous. Assume A has a method write(), calling write from D will result in an error – do you mean A::B::D‘s write(), or do you mean A::C::D‘s write()?

Solution: Make B and C inherit from virtual public A. We are then guaranteed to get only a single instance of the common base class.Then, the output is: