Multipath inheritance is to remove duplicate set of records in child class - Inheritance

Q.  In Multipath inheritance, in order to remove duplicate set of records in child class, we ___________ .
- Published on 17 Jul 15

a. Write Virtual function in parent classes
b. Write virtual functions is base class
c. Make base class as virtual base class
d. All of these

ANSWER: Make base class as virtual base class
 

    Discussion

  • Brijesh   -Posted on 08 Oct 15
    In Multipath inheritance, in order to remove duplicate set of records in child class, we Make base class as virtual base class.
    Suppose that we have two classes Test and Sports class. These classes are inherited from the Student base class. Therefore all the public and protected member of student class will be part of Test and Sports class. Again suppose that Result class is derived from Test and Sports class (Multiple Inheritance). So Result class has two copies of data member and member function of Student class. This situation will create problem. The solution of this problem is virtual base class. If we declare Student class as a virtual class while inheriting it, then only one copy will be inherited in Result class.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)