Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
'parameter' : cannot take the address of a template parameter
Remarks
You can't take the address of a template parameter unless it is an lvalue. Type parameters are not lvalues because they have no address. Non-type values in template parameter lists that are not lvalues also do not have an address.
Example
This is an example of code that causes Compiler Error C2891, because the value passed as the template parameter is a compiler-generated copy of the template argument.
template <int i> int* f() { return &i; }
Template parameters that are lvalues, such as reference types, can have their address taken.
template <int& r> int* f() { return &r; }
To correct this error, do not take the address of a template parameter unless it is an lvalue.