ambiguity in multiple inheritance
-
i have same function in both parent classes in multiple inheritance like show(); when i m am call function show(); compiler generate an error what is the solution of this problem
-
i have same function in both parent classes in multiple inheritance like show(); when i m am call function show(); compiler generate an error what is the solution of this problem
-
i have same function in both parent classes in multiple inheritance like show(); when i m am call function show(); compiler generate an error what is the solution of this problem
You have to specify which
show()
function has to be called:/* derived is an instance of your class */
derived.ParentClass1::show();
derived.ParentClass2::show();You may also put this code into a new member function using a different name like
showBoth()
or add functions for each:class derived : public ParentClass1, ParentClass2
{
// ...
void show1() { ParentClass1::show(); }
void show2() { ParentClass2::show(); }
void showBoth() { ParentClass1::show(); ParentClass2::show(); }
};