Virtual Base Class in C++

In a C++ programming language to overcome the ambiguity problem occurred due to multipath inheritance we use “virtual” keyword.

By using the “virtual” keyword we can declares the specified class virtual. 

When a class declared as virtual, then the compiler takes necessary precaution to avoid the duplication of member variable.

We can make a class virtual if it is a base class and is used by more than one derived classes as their base class. 

Example:   Write a program to declare virtual base classes. Derive a class using two virtual base class.

Output

Categories C++