可能性の重複:
Why does an overridden function in the derived class hide other overloads of the base class?損失
私はテンプレートパラメータとして使用されるクラスに継承されたメソッドを使用しての問題を抱えています。以下のように:
class D
{
};
class A
{
public:
void f(D &d){};
};
class B: public A
{
public:
void f(int) {};
};
template<typename F>
class C
{
public:
void doit() { D d; f->f(d); };
F *f;
};
int main()
{
C<B> cb;
cb.doit();
}
これが何であるか、私はそれをコンパイルしようとしています:
g++ testtemplate.cpp
testtemplate.cpp: In member function ‘void C<F>::doit() [with F = B]’:
testtemplate.cpp:28: instantiated from here
testtemplate.cpp:21: error: no matching function for call to ‘B::f(D&)’
testtemplate.cpp:14: note: candidates are: void B::f(int)
をしかし、私はボイドF(INT){}メソッドを削除した場合、コンパイラは、元のメソッドfを見つけます(D &d)。元のメソッドが新しいメソッドによって隠されているように見えます。私は理由を知りたい。
をhttp://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.8を見てください –