Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
If my understanding of your diamond problem is correct, then the problem in a such a case is that for e.g: There are four classes; A, B, C & D B & C inherit from A D inherits from B & C The problem here would be that D would be in a sense inheriting from class A twice; once from B and once from C. This would cause a problem since this would not only take up more space, but also when D calls some data member or method/function from A, the compiler would not know which one it should access. In such cases, A would be inherited virtually to ensure only one copy of A is inherited by D.
17th Oct 2017, 6:37 PM
Shuchita Dobhal
Shuchita Dobhal - avatar