Change template <class T, list<int> t>
to template <class T, list<int> &t>
:
template <class T, list<int> &t>
^^^ //note &t
class Tops
{
private:
list<stack<T>> tops;
public:
list getTops() {
}
};
The reason you can't do this is because non-constant expressions can't be parsed and substituted during compile-time. They could change during runtime, which would require the generation of a new template during runtime, which isn't possible because templates are a compile-time concept.
Here's what the standard allows for non-type template parameters (14.1 [temp.param] p4):
A non-type template-parameter shall have one of the following
(optionally cv-qualified) types:
- integral or enumeration type,
- pointer to object or pointer to function,
- reference to object or reference to function,,
- pointer to member.
Source Answer: https://stackoverflow.com/a/5687553/1906361