Possible Duplicate:
Why does an overridden function in the derived class hide other overloads of the base class?
I am having a problem with using an inherited method in a class used as a template parameter. like the below:
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();
}
This is what I get trying to compile it:
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)
However, if I remove the void f( int ) {} method, the compiler finds the original method f( D &d ). Looks like the original method is shadowed by the new one. I want to know why.