Ambiguity of Multiple Inheritance Assignment Help

Assignment Help: >> Inheritance - Ambiguity of Multiple Inheritance

Ambiguity in the Multiple inheritance

To prevent ambiguity among the derived class and one of the base classes or among the base class themselves, it is better to use the scope resolution operator::

With the data members and methods

#include <iostream.h>

class A

{

char ch;

public:

A(char c)

{

ch=c;

}

void show()

{

cout<<ch;

}

};

class B

{

public:

char ch; B(char c)

{

ch=c;

}

void show()

{

cout<<ch;

}

};

class C:public A, public B

{

public:

char ch;

C(char c1, char c2, char c3):A(c1),B(c2)

{

ch=c3;

}

};

void main()

{

C objc('a','b','c');

//       Objc.show(); Error: Field show is ambiguous in C

cout<<"Objc.A::show()=";

objc.A::show();

cout<<"Objc.B::show()=";

objc.B::show();

}

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