可能重复:
Why does an overridden function in the derived class hide other overloads of the base class?
我最近遇到了这个有趣的继承示例 -
class FirstClass
{
public:
void MethodA (int) { cout << "ONE\n";}
void MethodA (int, int) { cout << "TWO\n";}
};
class SecondClass : public FirstClass
{
public:
void MethodA (int) { cout << "THREE\n";}
};
int main ()
{
SecondClass a;
a.MethodA (1,1);
getch();
}
编译此代码时,您会收到以下错误消息 -
No matching function for call to 'SecondClass::MethodA(int, int)'
任何人都可以解释为什么我会收到此错误消息。 MethodA(int,int)应该由SecondClass继承。