Virtual base class is used to avoid ambiguity and multiple inheritance problems in C++. Some key points about virtual base class:
- A virtual base class is declared using the virtual keyword in a derived class.
- When a class is declared as a virtual base class, only one copy of that base class is shared among all the objects.
- It is used to resolve diamond problem in multiple inheritance.
- A virtual base class pointer can be used to access the single copy of the base class object.
2. What is multiple inheritance? Explain with an example.
Ans: Multiple inheritance is a feature of some object-oriented computer programming languages in which classes can inherit features from multiple base or parent classes.