Suppose there is this interface:
class A{
public:
virtual foo()=0;
};
And a class B which implements this interface:
class B:public A{
public:
virtual foo(){} //Foo implemented by B
}
Finally, a class C which has classes A and B as base classes:
Class C : public A, public B {
};
My question is, there is a way to tell the compiler that the implementation for foo is the one from class B without doing an explicit call to B::foo()?
As @BenVoigt pointed out in the comments, the below answer only works due to a bug in g++ (meaning it isn’t guaranteed to keep working, and it definitely isn’t portable). Thus, although it may do what you want if you use a particular (buggy) compiler, it isn’t an option you should use.
Do use virtual inheritance though.
This isn’t exactly the scenario that the code in the question implies, but the sentence
seems to be asking for syntax to distinguish between multiple base versions of a function without using the
::qualifier.You can do this with the
usingdirective:Of course, the code itself in the question doesn’t require this at all, as the other answers have pointed out.