I have this code (diamond problem):
#include
using namespace std;
struct Top
{
void print() { cout << \"Top::print()\" << e
Why is it ambiguous? I explicitly specified that I want
TopfromRightand not fromLeft.
That was your intent, but that's not what actually happens. Right::Top::print() explicitly names the member function that you want to call, which is &Top::print. But it does not specify on which subobject of b we are calling that member function on. Your code is equivalent conceptually to:
auto print = &Bottom::Right::Top::print; // ok
(b.*print)(); // error
The part that selects print is unambiguous. It's the implicit conversion from b to Top that's ambiguous. You'd have to explicitly disambiguate which direction you're going in, by doing something like:
static_cast(b).Top::print();