OBJECT-ORIENTED PROGRAMMING THROUGH C++
In this, one class is derived from two base classes and in turn these two classes are
derived from a single base class in known as Multi-path Inheritance.
//class A definition
class B: public A
//class B definition
class C: public A
//class C definition
class D :public B, public C
//class D definition
A is a base class. The classes B and C are derived from base class A. Both B and C
inherit properties of class A. Further, class D is derived from B and C.B and C have
same copies of members inherited from A. The same are inherited to D. Here,
ambiguity is generated. Hence, virtual keyword is used to avoid ambiguity.
Explain about virtual base classes with an example.
How can you overcome the ambiguity occurring due to multipath inheritance?
Explain with an example.
To overcome the ambiguity due to multipath inheritance the keyword virtual is
used. When classes are derived as virtual, the compiler takes essential caution to
avoid the duplication of members.
So, we make a class virtual if it is a base class that has been used by more than one
derived class as their base class.
DMSSVH COLLEGE OF ENGINEERING