Non-type template parameters (C++ only)

The syntax of a non-type template parameter is the same as a declaration of one of the following types:

Non-type template parameters that are declared as arrays or functions are converted to pointers or pointers to functions, respectively. The following example demonstrates this:

template<int a[4]> struct A { };
template<int f(int)> struct B { };

int i;
int g(int) { return 0;}

A<&i> x;
B<&g> y;

The type deduced from &i is int *, and the type deduced from &g is int (*)(int).

You may qualify a non-type template parameter with const or volatile.

You cannot declare a non-type template parameter as a floating point, class, or void type.

Non-type template parameters are not lvalues.

Related information