Bug 24893 - inherited polymorphic template class
Summary: inherited polymorphic template class
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.3
: P3 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-16 15:08 UTC by Frantz Maerten
Modified: 2005-11-16 15:17 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frantz Maerten 2005-11-16 15:08:33 UTC
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() ;
}
Comment 1 Andrew Pinski 2005-11-16 15:17:21 UTC
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.