+ 5
What is "DIAMOND PROBLEM" IN C++ plz can anyone explain it to me..??
inheritance
3 Answers
+ 5
it occurs as cpp allows multiple inheritance. some clashes might occur like if the child choose to call a method existing in two parents, that causes confusions
+ 1
I guess they did not really got it at https://medium.freecodecamp.org/multiple-inheritance-in-c-and-the-diamond-problem-7c12a9ddbbec.
Diamond problem occurs with multiple inheritance this way:
A A A
| | ==> / \
B C B C
\ / \ /
D D
If you call a function implemented in class A from an instance of class D (D->FunctionFromA()), compiler does not now whether it has to take the path via B or C. Class D as 2 times the base class A! Virtual inheritance solves this problem and ensures that B and C shares the same A.