CPP Programming
About Lesson

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:

  1. Function Over Riding
  2. 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

}

You cannot copy content of this page