2 回答
Either:
class Derived : public Base {
public:
using Base::getTwo; // Add this line
int getValue() {
// no matching function for call to ‘Derived::getTwo()’
return getTwo();
}
int getTwo(int) {
return 2;
}
}
Or
return Base::getTwo();
This is how the name lookup in C++ works:
namespace N1
{
int getTwo();
int getTwo(int, int);
namespace N2
{
int getTwo(int);
namespace N3
{
call getTwo(something char*);
}
}
}
The current context is N3. There is no getTwo
on this layer. Ok, go to the upper layer. N2 contains one definition for getTwo
. Compiler will try to use this definition and will not seach the upper context. The getTwo
from N2 hides all definitions for getTwo
on all upper layers. Sometimes this causes confusion with overloaded methods.
If you add using Base::getTwo;
, you actually add a definition proxy to the inner context. The definitions of the upper context temsellves are not visible. But the proxy is visible.