What is a virtual class?
The virtual class is a class that is assigned only once in memory, so children of this class use only one copy of this parental class that is created in memory. The class is a group of objects that share common features or attributes. The creation of a virtual class gives an object -oriented programming language the ability to use multiple heritage when second or more generational parental classes are derived from common basic ancestral classes. Depending on the referenced computer programming language, the "virtual" keyword, a similar keyword or syntax, and the semantics of the class are used to indicate that a certain class is considered virtual. In the programming language, such as C ++, the class can inherit all membership data and membership functions from both parental classes at once and have access to both sets of pardata and functions. Other languages that support multiple heritage include Perl, Python, TCl and Eiffel.
The problem occurs in several inheritance hierarchies, when two or more parents used to create a child class are originally derived from only one or the same grade of grandparents. This is called a diamond problem, the name stems from what the hierarchy would look like in this situation. When the compiler program attempts to install a class such as the grandchild class made of two parent classes with a common grandparents, two copies of the grandparents are made in memory, one for each parent.
Due to the ambiguity caused by multiple copies of the same grandparents in memory, the compiler is unable to find out which copy of the grandparents that the grandson should use to access grandfathers or functions. To remedy this situation, the G ++ grandparents are made on the Ual virtuisent when the parents declared. This causes the compiler to create only one copy of the grandparents in the memory that both parents share. Once the grandparents become a virtual class, the compiler has no probesLime with decisions on how the grandson should access grandparents because there is only one copy of the grandparents.
In the structuring of the class hierarchies, much attention should be paid, especially if they are included in the base for much larger hierarchies in the future. Correct use of the virtual class gives the class hierarchy a greater width in development; However, they have the potential to cause errors that are difficult to find. A study of solid computer programming principles will help ensure that the incorrect program organization does not occur.