Have a look at the following code:
struct A {
public:
virtual void f(){std::cout << "in A";};
};
struct B : A{
public:
virtual void f(){std::cout << "in B";};
int a;
};
struct C : B{
using A::f;
void test(){f();}
};
int main()
{
C c;
c.f(); // calls B::f, the final overrider
c.C::f(); // calls A::f because of the using-declaration
c.test(); //calls B::f
return 0;
}
Per my understanding, the B::f()
in C
should hide the A::f()
which is brought to C
by using-declaration; if so, then why does c.C::f()
still call A::f()
?
If c.C::f()
calls A::f()
, that should mean that in the scope of C
, f()
should be always refer to A::f()
, this is the function of the using-declaration. Then why in the C::test()
, call to f()
is still evaluated to B::f()
?