I have a template that depends on a constant which is in a header. Something like this :
The header that defines the constant:
// header1.hpp const int CONST_VALUE1 = 10;
The header where I have a template :
// header2.hpp extern const int CONST_VALUE2; template< int N > struct A { }; struct B { // some member functions A< CONST_VALUE2 > a; };
the source with the definition of B and the constant
// source2.hpp #include "header2.hpp" // implementation of B const int CONST_VALUE2 = CONST_VALUE1;
This of course doesn't work. The error is like this :
error: the value of 'CONST_VALUE2' is not usable in a constant expression
note: 'CONST_VALUE2' was not initialized with a constant expression
note: in template argument for type 'int'
Is there a work around? Or do I have to include the header1.hpp into header2.hpp?