+ 1

C++ supports multiple inheritance. What is the diamond problem that can occur with multiple inheritance. ?

plzz give an example

31st May 2017, 4:24 PM
Subhayan De
Subhayan De - avatar
3 ответов
+ 10
Think of a class A which has two subclasses: B and C. Let's say both B and C have a certain m() method (inherited from A) overriden with each of the two subclasses having different implementation of the method. And you have another class D which inherits from B and from C. It would look like this: (slashes marking inheritance paths) A / \ B C \ / D Now, if you want to address the m() method of an object of class D - which m() implementation is inherited by D: the one from B or from C? It is the so-called "diamond problem" because of the shape of the schema above. Different languages solve this problem differently (only those allowing multiple inheritance, of course).
31st May 2017, 5:13 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
Take a look here: https://www.youtube.com/watch?v=7APovvvftQs It mentions the diamond inheritance too.
31st May 2017, 4:46 PM
Dennis
Dennis - avatar
+ 1
thanks. .
9th Jun 2017, 1:59 PM
Subhayan De
Subhayan De - avatar