Ambiguity in Multiple Inheritance occurs when more than one base classes have a function with same name. When such a function has to be accessed through the object of derived class, compiler gives error showing ambiguous function definition.
Ambiguity in Multiple Inheritance can be solved in two ways:
- Function Over Riding
- Scope Resolution Operator
FUNCTION OVERRIDING:
When a derived class has re-defined a member function which was already defined in its base class it is known as Function Over Riding
Class father
{
Void doEducation()
{
Cout<<”do Engineering”;
}
};
Class mother
{
Void doEducation()
{
Cout<<”do Medicine”;
}
};
Class son: public father, public mother
{
void doNothing()
{
cout<<”I m confused”;
}
};
main()
{
son s;
s.doEducation(); // ambiguity occurs due to Multiple Inheritance
}