Originally Posted by
grumpy
The call D::B::f(), no matter how you specify it, is ambiguous unless B is a virtual base. So the call is not possible.
Grumpy, i worked a little to produce this minimalistic example, so to keep things simple. one thing I know for sure, is that I don't want B to be a virtual base class.
I'm not convinced that this call shouldn't be possible. It says in the Standard (10.2.5) that for nonvirtual base classes one uses explicit qualification (an inheritance path) to specify which sub-object is meant. I've seen this exemplified with fields, but it should work with functions.
Furthermore: I was not *very* suprised to see that Visual Studio compiles and calls the implementation of f() that I would expect! If you wanna try it:
Code:
class B
{
public:
char mC;
B(char c) : mC(c) {}
virtual char f() {return mC;}
};
class C : public B
{
public:
C() : B('C') {}
virtual char f() {return 'A';}
};
class D : public C, public B
{
public:
D() : C(), B('D') {}
virtual char f() {return B::f();} // error: cannot call member function ‘virtual void B::f()’ without object
};
Code:
void main() { std::cout<<D().f();
}