Тёмный
No video :(

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

tech fort
Подписаться 10 тыс.
Просмотров 17
50% 1

#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

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии    
Далее
Средневековый киборг
00:39
Просмотров 518 тыс.
Coding Was HARD Until I Learned These 5 Things...
8:34
Средневековый киборг
00:39
Просмотров 518 тыс.