Diamond inheritance / Ambiguities in inheritance

Hi friends,
Here I am explained the Diamond Inheritance and Ambiguities in inheritance. Just watch out the below image and with my explonation.

The above figure illustrates the diamond inheritance. The class IOS is the base class for both IStream and OStream classes. Each of those classes formed with single inheritance. The class IOStream inherits from both IStream and OStream classes. This class object will provide the functionality of both IOStream and OStream classes. In multiple inheritance hierarchies, the situation described in above figure is referred to as Diamond Inheritance.

There would be seemed a problem in IOStream class. Because the class IOStream contain two copies of the members of class IOS. One inherited via the class IStream and another one inherited via the class OStream. Such a situation would be ambiguous and would result in a compilation error. Because the compiler wouldn’t know which version of members from class IOS to use.

In this situation, the virtual base class solves the problem of inheriting duplicate copies of an indirect base class.


No comments: