31 Confusion in multiple inheritance, Hybrid inheritance zoom | C++ Programming Tutorial for beginn

Опубликовано: 07 Март 2021
на канале: tech fort
17
0

#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 "\n\n freeHouseScheme from central govt. 5 Lakh" endl;
}
};
//Base class 2
class StateGovt{
public :
void freeHouseScheme(){
//body of the freeHouseScheme StateGovt
cout "\n\n freeHouseScheme from STATE govt. 2.5 Lakh " endl;
}
};
class Citizen:public CentralGovt,public StateGovt{
public :
int cId;
void getBenefit(){
cout "\n\n 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