got “cannot appear in a constant-expression” when using template

A non-type template argument needs to be a compile-time constant. Casting an int to a const int does not make it a compile-time constant. You either need to use 10 directly:

CAT<10> cat;

or make i a const int:

const int i = 10;
CAT<i> cat;

Leave a Comment