Hel wrote:

Hi,

I'm sure you are familiar with this problem:

A.h:

template <unsigned Nstruct A {

static const unsigned a;

};

template <const unsigned A<0>::a = 1;

template <unsigned Nconst unsigned A<N>::a = A<N-1>::a*N;

Now if I include A.h from multiple .cpp files I get a linking error

because A<Nhas multiple definitions.

Because A<0>::a has multiple definitions actually. Try just moving that

one.

BTW, you might consider an alternative design, since you are dealing

with integral values:

template < unsigned N >

struct A

{

enum { a = A<N-1>::a * N };

};

template <>

struct A<0>

{

enum { a = 1 };

};

Numerous benefits here. For instance, I don't believe any of the A

objects are actually instantiated and therefore, unlike your static int

version that will instantiate all in between, there is only one static

value that is generated by the metaprogram.