Ambiguity in Multiple Inheritances
Ambiguity in multiple inheritances
Consider an example of multiple inheritances in which there are two base classes having functions with the same name and a class derived from both these base classes having no function with this name.
Void show ()
Cout<<”\n class A”;
Void show ()
Cout<<”\n class B”;
Class C: public A, public B
Void main (0
Obj. Show ();
The members are ambiguous without scope resolution operator when the member function show () is accessed by the derived class object, naturally, the compiler can’t distinguish between member function of the class A and B.
The problem is resolved using scope-resolution operator to specify the class in which the function lies. Thus,
Obj.y:: show ();
Refers to the function in the B class. Thus, the scope – resolution operator resolves the ambiguity.
- Overriding Member Function in C++ Overriding member function We can define data member and member...
- Virtual base class in C++ Virtual base class in C++ Consider the situation, with a...
- Inheritance in C++ Inheritance in C++ Inheritance is one of the most important...
- Defining Member Function In C++ Class methods definitions (Defining the member functions) Member functions can...
- Type of Inheritance Type of Inheritance Multiple inheritance When a derived class is...