Hi all, We just found a bug while compiling the following code. The derived template class doens't know the pure virtual method from its parent class when this template class has a method with the same name, but with different arguments: class A { public: virtual void doit() = 0 ; } ; template <typename T> class B: public A { public: virtual void doit(double) {} } ; class C: public B<double> { public: virtual void doit() {} } ; int main() { A* a = new C ; B<double>* b = new C ; a->doit() ; // ok // Compile error with gcc-3.4.3: // error: no matching function for call to `B<double>::doit()' // note: candidates are: void B<T>::doit(double) [with T = double] b->doit() ; }
First this has nothing to do with templates, you can reproduce the error message without templates. Second this is how C++ works. doit(double) in B<T> hides doit(void) in A as it is the same name. The way to fix it would either to do: b->A::doit() ; or: Change defintion of B to include a using statement like: template <typename T> class B: public A { public: virtual void doit(double) {} using A::doit; } ; This makes both doit visible in B<T>. In fact you will have the same issue trying to call doit(double) in C, you solve it the same way.