C++ static const array initialization in template class
arrays, c++, initialization, static, templates
Solution
you declared a static const int array in your class,so you must define the static member out of the class declaration,just like this:
template<unsigned N>
class XArray
{
public:
static const int array[N];
};
template<unsigned N>
const int XArray<N>::array[N] = {1,2,3,4,5};
But something you must pay attention to is that: when you use this template you must make sure that the "N" bigger than the number of your initialized array;
Problem
I have the following template class: ``` template <unsigned N> class XArray { static const int Xdata[N]; }; ``` I want to initialize the static const array for each `XArray<N>` I used, for example, let `XArray<N>::Xdata = {1, 2, 3, ..., N}`. How to make it?