Ambiguity means when the base and derived class have the same name of member function OR data members.
These are the two ways to access the overridden members/solve the overridden problem in inheritance.
1) Accessing the overridden members by the help of a member function of a base class
2) Accessing the overridden members by the help of a derived class object
In both the cases, the classname::name of member should be specified.
1)By the help of a member function of a base class
Clue for writing program is that we need to access the overridden members.
That means the base and derived class will have same function name and data members name.
We will be using the help of member function of a base class.
We will do it by Base::input(). Now below is the source code.
using namespace std;
cout<<"enter the value of n of a base class";
class Derived:public Base
cout<<"enter the value to n of a derived class";
cout<<"the total value is"<<Base::n+n;
enter the value of n of a base class 5
enter the value to n of a derived class 2
the total value is 7
In the next blog post, we will discuss about the second part (accessing overridden members of a base class by the help of derived class objects.)
Here is the link to the next blog post-: