Ambiguity means an unclear situation. Two base
classes can have functions with same name while the class derived from both the
base classes has no function with same name. How do objects of the derived
class access the correct base class function?
Now
the program has derived class medical with two base classes, namely student and
academic. We see both the base classes have functions with same name, which
certainly lead to a problem when a class derives features from both. The
derived class will have two different functions with the same name. The
ambiguity occurs only when we use the name of the function. To call a function,
the name of the function alone is insufficient, since the compiler is meant. To
overcome this problem the functions are invoked long with name of class and
scope resolution operator as follows:
student::output()
academic::output()
The
compiler distinguishes the above two member functions by identifying them with
the class to which they belong. So scope resolution operator plays an important
role to point the objects and map the respective functions.
0 comments:
Post a Comment