As I understand it, the meaning of the template should be known at compile time. so I am writing a small example, just to see that I get it, but by the way, I did not. so I get the following:
`defValue' cannot appear in a constant-
expression
Can anyone ask what the problem is and how to fix it?
#include <iostream>
template <class T,T defaultVal, int dim=255>
class Vec
{
T _vec[dim];
int _dim;
public:
Vec () : _dim(dim)
{
for (int i=0;i<_dim;++i)
{
_vec[i] = defaultVal;
}
}
~Vec () {};
};
int main ()
{
int defValue = 0;
Vec < int,defValue > vecWithDefVal;
}
source
share