4

I have the same warning message as in a previous discussion but I don't understand how to solve it:

warning: too many template headers for foo<1>::value (should be 0) int const foo<1>::value = 1;

The warning message appears when one wants to use the following toy header:

#ifndef FOO
#define FOO

template<int T>
struct foo;

template<>
struct foo<1>
{ static int const value; };

template<>
int const foo<1>::value = 1;

#endif

Can you explain me what the problem is here?

Aleph
  • 1,343
  • 1
  • 12
  • 27

1 Answers1

6

The template<> in your definition of foo<1>::value is extraneous. Remove it:

template<int T>
struct foo;

template<>
struct foo<1>
{ static int const value; };

int const foo<1>::value = 1;

clang++ gives you a much better error:

prog.cc:11:1: error: extraneous 'template<>' in declaration of variable 'value'
template<>
^~~~~~~~~~
1 error generated.

live example on wandbox

Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416