8th Sep 2020, 3:02 AM
Kajal Kumari
4 Antworten
+ 11
Kajal Kumari You're Inheriting class A in both class B and class C. So class B and class C will contain the function " showa( ) " of class A. By inheriting class A and class B virtually in class D your errors for ambiguity will remove. But there will be one error - " showc wasn't declared in this scope " Reason - Because you want print 'C' by showc() which is in Derived class D " without inheriting class C " ( as class C contains showc( ) function ) So , to remove this error you have to inherit class C ( instead of class A ) in derived class D . You can also do this as Robert Atkins code but in his code there is " multilevel inheritance ". And for your code - https://code.sololearn.com/cyLqwzbYAoN4/?ref=app
8th Sep 2020, 5:50 AM
Vinesh Wadhwani
Vinesh Wadhwani - avatar
+ 1
I think the problem lies in the fact that class D is inheriting from class B and class A, since class B already inherits from class A it confuses the compiler throwing that ambiguity error, here i modified your code a bit https://code.sololearn.com/cnMe87IzY6E5/?ref=app Also, just for future posts, please have some organization to your code, indents and such, not only will it help out other readers of your code, but also yourself when you come back to it at a later date.
8th Sep 2020, 3:53 AM
StealthyTaco
StealthyTaco - avatar
+ 1
I can't use virtual function here???to remove ambiguity error
8th Sep 2020, 4:52 AM
Kajal Kumari
+ 1
Thanku sooo much
8th Sep 2020, 6:09 AM
Kajal Kumari