First I would like to acknowledge that there are many questions with similar titles and subject matter. I'm fairly certain mine is unique from them.
Given the code
struct Top {
int get() {
return 0;
}
};
struct Mid1 : Top {
int get() {
return 1;
}
};
struct Mid2 : Top {
int get() {
return 2;
}
};
struct Bottom : Mid1, Mid2 {
};
int main(int argc, char ** argv) {
Bottom b;
std::cout << b.Mid1::get();
std::cout << b.Mid2::get()
std::cout << b.Top::get();
}
I get an error on the line trying to access Top::get()
with the error (using gcc mingw-w64)
error: 'Top' is an ambiguous base of 'Bottom'
std::cout << b.Top::get();
I get an error. How would one signal to the compiler to call Top::get
on a specific inheritance path in this case?