Ambiguity in Single Inheritance Assignment Help

Assignment Help: >> Inheritance - Ambiguity in Single Inheritance

Ambiguity in Single Inheritance

When a data member and member function are described along with the similar name in both the base and the derived classes, those names must be without ambiguity. The scope resolution operator (::) might be used to refer to any base member explicitly. This permits access to a name which has been redefined in the derived class.

For instance, The following program segment describes how ambiguity occurs whenever the getdata() member function is accessed from the main() program.

class baseA

{

public:

void getdata()

{

....

};

class baseB

{

public:

....

....

}

void getdata()

{

....

...

....

}

};

class derivedC:public baseA, public baseB

{

public:

};

void main()

{

void getdata()

{

....

....

....

}

derivedC obj;

obj.getdata();

}

The members are ambiguous without scope operators. Whenever the member function getdata() is accessed through the class object, generally, the compiler cannot distinguish among the member function of the class baseA and the class baseB. Thus it is necessary to declare the scope operator explicitly to call a base class member as description given below:

obj.baseA::getdata();

obj.baseB::getdata();

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd