
GNU nano 2.9.1 test.cpp Modified
/********************************************************************************************************
*************Designed and Developed by V2Geeks******************************************
********************************************************************************************************/
// Example of
Ambiguity problem and it’s solution in multiple inheritance
#include<iostream.h>
#include<conio.h>
class A{
public:
void display()
{
cout<<"Hello from A \n";
}
};
class B
{
public:
void display()
{
cout<<"Hello from B \n";
}
};
class C : public A, public B // now C is child of Both A and B
{
// now C have display function of both class A and class B
};
void main()
{
C objC; //now objC have display() function of both class
clrscr();
// objC.display(); //ERROR:It is ambiguous to which display() to be called
//so solution is scope resolution operator
objC.A::display(); //now ambiguity problem resolved and will call A's display()
objC.B::display(); //now ambiguity problem resolved and will call B's display()
getch();
}