Virtual Inheritance

Virtual inheritance is a topic of object-oriented programming. It is a kind of inheritance in which the part of the object that belongs to the virtual base class becomes a common direct base for the derived class and any other class that derives from it. In other words, if class A is virtually derived from class V, and class B is derived (directly or indirectly) from A, then V becomes a direct base class of class B and any other class derived from A. The best-known language that implements this feature is C++.

This feature is most useful for multiple inheritance, as it makes the virtual base a common subobject for the deriving class and all classes that are derived from it. This can be used to avoid the problem of ambiguous hierarchy composition (known as the "diamond problem") by clarifying ambiguity over which ancestor class to use, as from the perspective of the deriving class (B in the example above) the virtual base (V) acts as though it were the direct base class of B, not a class derived indirectly through its base (A).

It is used when inheritance represents restriction of a set rather than composition of parts. In C++, a base class intended to be common throughout the hierarchy is denoted as virtual with the virtual keyword.

Read more about Virtual Inheritance:  The Problem, The Solution

Famous quotes containing the words virtual and/or inheritance:

    Neither dead nor alive, the hostage is suspended by an incalculable outcome. It is not his destiny that awaits for him, nor his own death, but anonymous chance, which can only seem to him something absolutely arbitrary.... He is in a state of radical emergency, of virtual extermination.
    Jean Baudrillard (b. 1929)

    Late in the afternoon we passed a man on the shore fishing with a long birch pole.... The characteristics and pursuits of various ages and races of men are always existing in epitome in every neighborhood. The pleasures of my earliest youth have become the inheritance of other men. This man is still a fisher, and belongs to an era in which I myself have lived.
    Henry David Thoreau (1817–1862)