template, static const int and overloading

Petter Urkedal petter@matfys.lth.se
Wed Nov 10 03:23:00 GMT 1999


When static const int member is used as the template parameter to
an argument of a member function, and the member function is
defined out-of-class, its prototype is not recognized (at least
in the case shown below).

The simple workaround is to use an enum, which is probably better
than static const int anyway.

Please, CC me!

Cheers,
Petter.


[---]$ gcc -v
Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.96/specs
gcc version 2.96 19991107 (experimental)

[---]$ uname -a
Linux katsumoto.matfys.lth.se 2.2.5-22 #1 Wed Jun 2 09:02:27 EDT 1999
i586 unknown

[---]$ gcc tempmemb.cc
tempmemb.cc:10: prototype for `void tau<T>::find (alpha<tau<T>::D> &)
const' does not match any in class `tau<T>'
tempmemb.cc:7: candidate is: void tau<T>::find (alpha<tau<T>::D> &)
const
tempmemb.cc:10: template definition of non-template `void tau<T>::find
(alpha<tau<T>::D> &) const'

[---]$ cat tempmemb.cc
template<int N> struct alpha {};

template<typename T>
  struct tau {
      static const int D = T::some_CT_int_member;
      typedef alpha<D> beta;
      void find(beta&) const;
  };

template<typename T> void tau<T>::find(beta& x) const {}

[---]$


More information about the Gcc-bugs mailing list