What is virtual heredity?
virtual inheritance is a type of inheritance in which the implementation of a super class is incomplete and a subclass is required for the complete definition of the object. This type of inheritance can be used in conjunction with only and multiple inheritance, but most often used in multiple inheritance. Any class that inherits from the virtual base class becomes a direct subcontrary of this basic class. The virtual basic class can rely on subclass to implement all its methods, but this is not a request.
C ++ is the most known computer language for using virtual heritage. A "virtual" keyword is used to declare virtual heritage in C ++. Both superclass and subclass must declare virtual methods using "virtual" keywords. This says the C ++ compiler that SuperClass is incomplete and must get information from the subclass to complete it. Using a subclass to complete a super class does not mean that subclass switches to each other if they have a base class and insteadC ++ compiler takes care of determining what pieces go with each object.
Because virtual basic class is required for virtual inheritance, global features in C ++ cannot be declared virtual. This type of inheritance can only be used in adherence to the principles of programming (OOP) with object -oriented. The reason is that global functions are not associated with a particular class, so they are usually independent. Without the inheritance of superclass and subclass, it cannot happen, so global function and virtual inheritance are excluded. Global functions can theoretically be used inside virtual functions, but the opposite may not always work.
virtual inheritance is used to solve many programming problems and one of the most useful is the solution of ambiguity. In more inheritance can have the basic class A, which has two subclass, B AC, and then class D, which inherits from both classes B and C. This formula is normally nThe "Diamond of Death" is, because if they have classes A, B and C of the same method, it is not possible for class D to determine which implementation it should use. Virtual inheritance solves this problem because the implementation of each class remains different and therefore unambiguous. This distinction is solved by specialized internal objects called virtual tables (vtables) that monitor each type of object, but these tables may not be explicitly manipulated by a programmer because they are built into the language.