egcs-g++-971215: template specialization problem

Dirk Herrmann dirk@ida.ing.tu-bs.de
Thu Dec 18 01:15:00 GMT 1997


Hello everybody!

The following code does not compile:



> cat test.cc 
template <class T>
struct X
{
    virtual void f(int) const;
};

template <class T>
struct Y: public X<T>
{
    virtual void f(int) const;
};

template <class T>
void Y<T>::f(int) const
{
}

template <>
void Y<bool>::f(int) const;

> g++ test.cc 
test.cc:19: prototype for `void Y<bool>::f(int) const' does not 
match any in class `X<bool>'
test.cc:4: candidate is: void X<bool>::f(int) const



It _does_ compile if I not just give a prototype for 
'void Y<bool>::f(int) const', but also a definition. This on the other
hand leads to 'multiply defined' messages when including the header file
into two or more .cc files.




BTW1: If any of my bug reports contains code you might want to include
      in the set of regression tests, please feel free to do so.
      (Because of the simplicity of these examples, I believe you
      would have done anyway. Just in case of doubt...)
BTW2: Thanks to everybody answering this and previous questions of mine.

Best regards,
Dirk Herrmann




More information about the Gcc-bugs mailing list