I've already reviewed several similar questions at StackOverflow, but nothing helps. I can't understand why the keyword using in my class NetflixCanada does not resolve the ambiguity.
What I want to achieve: to access 2nd time a private method from NetflixUkraine class.
Anyway, this is the code:
#include <iostream>
using namespace std;
void greetings(){
cout << "\e[1mHi! This is a Netflix country review:\e[0m\n";
}
class NetflixUkraine {
private:
string mostPplrBrowserFrNTflx;
public:
string countryName;
int amountMedia = 5000;
void uniqueMedia(){
cout << "We have john Wick II\n";
}
void setBrowser(string amostPplrBrowserFrNTflx){
if (amostPplrBrowserFrNTflx == "Chrome" || amostPplrBrowserFrNTflx == "Firefox" ||
amostPplrBrowserFrNTflx == "Safari" || amostPplrBrowserFrNTflx == "Opera"){
mostPplrBrowserFrNTflx = amostPplrBrowserFrNTflx;
}
else {
mostPplrBrowserFrNTflx = "\nCannot define a web browser!\n";
}
}
string getBrowser(){
return mostPplrBrowserFrNTflx;
}
};
class NetflixPoland: public NetflixUkraine {
public:
void uniqueMedia(){
cout << "We have john Wick II and III\n"; //method overriding
}
string doPolesLoveNtflx(bool answer){ //extending inheritance
if (answer == 1){
return "Poles love Netflix";
}
else{
return "Poles don't love Netflix";
}
}
};
class NetflixCanada: public NetflixUkraine, public NetflixPoland{
public:
using NetflixUkraine::setBrowser;
};
int main()
{
greetings();
//printing output
NetflixUkraine library1;
library1.countryName = "Ukraine";
cout<< library1.countryName<<endl << library1.amountMedia << endl;
library1.uniqueMedia(); //printing out the unique media
NetflixPoland library3;
library3.countryName = "\nPoland";
cout << library3.countryName<< endl;
library3.uniqueMedia();
cout << library3.doPolesLoveNtflx(true) << endl;
//adding a fav browser for watching Netflix
library3.setBrowser("Chrome");
cout << "most popular browser for watching Netflix: " << library3.getBrowser() << endl;
NetflixCanada library4;
library4.NetflixUkraine::setBrowser ("Chrome");
return 0;
}
Output:
[12inheritance.cpp 2020-10-10 11:41:07.556]
,,12inheritance.cpp:65:7: warning: direct base ‘NetflixUkraine’ inaccessible in ‘NetflixCanada’ due to ambiguity
65 | class NetflixCanada: public NetflixUkraine, public NetflixPoland{
| ^~~~~~~~~~~~~
12inheritance.cpp: In function ‘int main()’:
12inheritance.cpp:96:30: error: ‘NetflixUkraine’ is an ambiguous base of ‘NetflixCanada’
96 | library4.NetflixUkraine::setBrowser ("Chrome");
| ^~~~~~~~~~
Your compiler can not distinguish between:
NetflixCanada::NetflixUkraine::setBrowser
and
NetflixCanada::NetflixPoland::NetflixUkraine::setBrowser
As mention in the comments, read about "The deadly diamond of death"