+ 1
C++ supports multiple inheritance. What is the diamond problem that can occur with multiple inheritance. ?
plzz give an example
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).
+ 2
Take a look here:
https://www.youtube.com/watch?v=7APovvvftQs
It mentions the diamond inheritance too.
+ 1
thanks. .