C++ Programming :: Objects and Classes - Discussion
88 / 41
What is the use of virtual base class in c++
AMultiple lines between derived classes.
BMultiple lines between base classes.
Cinheritance
DNone of these
Show Explanation
Virtual keyword, when assigned to base class while deriving a new class helps to prevent having multiple instances of the base class. so that there will be no ambiguity.
Lets say class b and class c are derived classes of class a and class a has a member function void foo(). Now, if we derive class d from both class b and class c, then the statement d.foo() creates ambiguity between the versions of class b and class c. To avoid this behavior, we must use Virtual keyword before the base class ('a') while deriving the classes b and c.
Asked In ::
The answer is Option C, inheritance.
Virtual keyword, when assigned to base class while deriving a new class helps to prevent having multiple instances of the base class. so that there will be no ambiguity.
Lets say class b and class c are derived classes of class a and class a has a member function void foo(). Now, if we derive class d from both class b and class c, then the statement d.foo() creates ambiguity between the versions of class b and class c. To avoid this behavior, we must use Virtual keyword before the base class ('a') while deriving the classes b and c.
Read Full Answer
Report Error
Please Login First Click Here