
Static member definition of template class fails
Quote:
>Hi,
>I have a template class which has been cut down to the following minimal
>definition...
>template <class T> class C
>{
>public:
> static int val;
>};
>I wanted to define the member variable with a constant initialiser like
>this...
>template <class T> int C<T>::val(1);
>But this throws a compiler error stating that val is not a function:
>error C2059: syntax error : 'constant'
>error C2063: 'val' : not a function
>error C2040: 'val' : 'int (void)' differs in levels of indirection from
>'int'
>However, if I specialise the template, like this for example...
>template<> int C<int>::val(1);
>the compiler is quite happy.
>Note that the both definitions work fine under the HP aCC compiler.
>I have tried this on MSVC 5, 6 and 6+service pack 3, with the same problem.
>Is this a compiler bug and is there a fix/workaround?
It's a bug. Here's a workaround:
template <class T> int C<T>::val = 1;
--
Doug Harrison
Visual C++ MVP