Consider I have a class template which takes an array as an argument:
template <int N, const float numbers[N]>
class TemplateClass
{
public:
TemplateClass()
{
for (int i = 0; i < N; i++)
{
cout << numbers[i] << endl;
}
}
};
I can use it successfully like this:
const int N = 3;
extern const float Constants[N];
const float Constants[N] = { 2.0f, 2.1f, 2.2f };
int main()
{
TemplateClass<3, Constants>();
return 0;
}
However, my attempts at moving the constructor method body outside of the class declaration were in vain:
// Fails with:
// error C2440: 'specialization' : cannot convert from 'const float *' to 'const float [3]'
template <int N, const float numbers[N]>
TemplateClass<N, numbers>::TemplateClass()
{
for (int i = 0; i < N; i++)
{
cout << numbers[i] << endl;
}
}
// Fails with:
// error C3860: template argument list following class template name must list parameters in the order used in template parameter list
// error C3855: 'TemplateClass<N,numbers>': template parameter 'numbers' is incompatible with the declaration
template <int N, const float* numbers>
TemplateClass<N, numbers>::TemplateClass()
{
for (int i = 0; i < N; i++)
{
cout << numbers[i] << endl;
}
}
This is observed on both VC++11 and VC++12 compilers. How do I solve this?