How to pass non type arguments in generic classes in C++?

Non type arguments can be passed to generic classes. Non type parameters can only be integers, pointers and references. A non type parameter is actually a constant and its value will not change. They can be used to set dimensions of an array. In the below given example, int x is the non type argument.

template <class T, int x> class test {

T a[x];


test() {

register int b;

for(b=0; b<x; b++) b[i] = i;


T &operator[](int i);


Leave a Reply