#Confusion/Ambiguity in Multiple inheritance:
- Confusion occurred in using the multiple inheritance when a function with the same name occurs in more than one base class.
#include iostream
using namespace std;
//Base Class 1
class CentralGovt{
public :
void freeHouseScheme(){
//body of the freeHouseScheme CentralGovt
cout "
freeHouseScheme from central govt. 5 Lakh" endl;
}
};
//Base class 2
class StateGovt{
public :
void freeHouseScheme(){
//body of the freeHouseScheme StateGovt
cout "
freeHouseScheme from STATE govt. 2.5 Lakh " endl;
}
};
class Citizen:public CentralGovt,public StateGovt{
public :
int cId;
void getBenefit(){
cout "
Citizen want to get benefit from central ,state govt " Id endl;
}
};
int main(){
Citizen cc;
cc.cId=67899;
cc.CentralGovt::freeHouseScheme();
cc.StateGovt::freeHouseScheme();
cc.getBenefit();
getchar();
return 0;
}
To avoid ambiguity/confusion situation we can use scope/class resolution operator
5 сен 2024