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:

    Tragedy dramatizes human life as potentiality and fulfillment. Its virtual future, or Destiny, is therefore quite different from that created in comedy. Comic Destiny is Fortune—what the world will bring, and the man will take or miss, encounter or escape; tragic Destiny is what the man brings, and the world will demand of him. That is his Fate.
    Susanne K. Langer (1895–1985)

    It is very difficult to be wholly joyous or wholly sad on this earth. The comic, when it is human, soon takes upon itself a face of pain; and some of our griefs ... have their source in weaknesses which must be recognized with smiling compassion as the common inheritance of us all.
    Joseph Conrad (1857–1924)