Possible Duplicates:
C++ overload resolution
Why does an overridden function in the derived class hide other overloads of the base class?重載方法
爲什麼以下示例:
class A {
public:
void f(int x){ }
};
class B : public A {
public:
void f(float a, int b){ }
};
int main(){
B *b = new B;
b->f(1);
};
原因:
TEST.CPP:在函數 '詮釋主()': TEST.CPP: 13:錯誤:沒有用於調用'B :: f(int)'的匹配函數 test.cpp:8:注意:候選是:void B :: f(float,int)
f(int)
和f(float, int)
具有不同的簽名。爲什麼會造成錯誤?
編輯
我理解它藏了起來。我在問爲什麼是這種情況?
我想這是隱藏的,因爲B :: f和A:f在不同的範圍。 – pic11 2011-04-12 13:58:54