The "value" of the template must be present at compile time.
template<int x> struct X {};
Even if you donβt bind the link or pass a pointer here, the compiler must know the value of the elements passed at compile time.
Replacing int &x with int x is entirely here. Material about int & answered correctly. I just wanted to point out that it applies to all non-typed template arguments.
- The "value" of a link is a link (in most cases, the dependency depends on the pointer)
- The address of the object must be known at compile time
- The "value" of the
template<int*> pointer is the address ...- ... which, in turn, should also be known here.
- A "value" of type value is the value itself, which must also be known at compile time
X<local_var> x; // will not work, local_var does not exist at compile time X<1> x; // works since 1 is known
I just wanted (in addition to Andy's answers) to prevent any conclusions that would suggest using a value type instead of a reference.
source share