This documentation is archived and is not being maintained.

Compiler Error C2975

Error Message

'arg' : invalid template argument for 'type', expected compile-time constant expression

The template argument does not match the template declaration; a constant expression should appear within the angle brackets. Variables are not allowed as template actual arguments. Check the template definition to find the correct types.

The following sample generates C2975:

// C2975.cpp
template<int I>
class X {};

int main() {
   int i = 4, j = 2;
   X<i + j> x1;   // C2975
   X<6> x2;   // OK

C2975 will also occur when you use __LINE__ as a compile-time constant with /ZI:

// C2975b.cpp
// compile with: /ZI
// processor: x86
template<long line> 
void test(void) {}

int main() {
   test<__LINE__>();   // C2975
   test<__LINE__>();   // OK