Opentopia Directory Encyclopedia Tools

Diamond problem

Encyclopedia : D : DI : DIA : Diamond problem


In object-oriented programming languages with multiple inheritance, the diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If a method in D calls a method defined in A, which class does it inherit from, B or C?

diamond.png

It is called the 'diamond' problem because of the shape of the class inheritance diagram in this situation. Class A is at the top, both B and C separately beneath it, and D joins the two together at the bottom to form a diamond shape.

Different programming languages have addressed this problem in different ways:

The diamond problem is not limited to inheritance. It also seems to arise when header files A, B, C, and D "#include" one another in a diamond as above and separate precompiled headers are created from B and C. If these two precompiled headers are combined, declarations in A are duplicated; the "#ifndef" convention (see the header file article) is ineffective.

See also

 


From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.

Search Titles
0123456789
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ?

E-mail this article to:

Personal Message: