У меня есть шаблон, который зависит от константы, которая находится в заголовке.Примерно так:
Заголовок, который определяет константу:
// header1.hpp
const int CONST_VALUE1 = 10;
Заголовок, где у меня есть шаблон:
// header2.hpp
extern const int CONST_VALUE2;
template< int N >
struct A
{
};
struct B
{
// some member functions
A< CONST_VALUE2 > a;
};
источник с определением B и константой
// source2.hpp
#include "header2.hpp"
// implementation of B
const int CONST_VALUE2 = CONST_VALUE1;
Это, конечно, не работает.Ошибка такая:
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'
Есть ли обходной путь?Или я должен включить header1.hpp в header2.hpp?