可能重复:
overloaded functions are hidden in derived class无法使用基类的方法
看来我不能直接使用在派生类从基类的方法是当它们存在在两个重载基类和C++中的派生类。以下代码会产生错误no matching function for call to ‘Derived::getTwo()’
。
class Base {
public:
int getTwo() {
return 2;
}
int getTwo(int, int) {
return 2;
}
};
class Derived : public Base {
public:
int getValue() {
// no matching function for call to ‘Derived::getTwo()’
return getTwo();
}
int getTwo(int) {
return 2;
}
};
如果我改变return getTwo();
到return ((Base*) this)->getTwo()
,它的工作原理,但是这看起来丑陋给我。我怎样才能解决这个问题?
P.S.如果有问题,我使用g ++ 4.7和std = gnu ++ c11选项。
这将肯定会作为重复关闭,但同时,快速的答案是在类范围中将'Base :: getTwo'添加到您的Derived'定义中。 – ildjarn 2012-07-14 00:26:45