What is the need for Virtual base classes?
- Required in scenarios of multiple inheritance where the derivation is like diamond.
- Compiler reports an error since there is a ambiguity since the derived class (Derived3) sees 2 instance of base class (Base).
- Using the keyword virtual in the derived classes (Derived1, Derived2) resolves this ambiguity by allowing them to share a single instance of base class.
EXAMPLE: Demonstrate the compilation error in the Diamond problem
0 comments:
Post a Comment