I'm trying to create a parameter pack with a default pointer type:
template<int*... T>
void f() {}
I get error with this code:
int main(){
int* a = new int(5);
f<a>();
}
But if I do this, I don't get a error:
int main(){
f<nullptr>();
}
Why?
Error:
./example.cpp: In function 'int main()': ./example.cpp:6:7: error: the
value of 'a' is not usable in a constant expression
f<a>();
^ ./example.cpp:5:10: note: 'a' was not declared 'constexpr'
int* a = new int;
^ ./example.cpp:6:10: error: no matching function for call to 'f<a>()'
f<a>();
^ ./example.cpp:2:6: note: candidate: 'template<int* ...T> void f()' void f() {}
^ ./example.cpp:2:6: note: template argument deduction/substitution failed: ./example.cpp:6:10: error: 'a' is not a
valid template argument because 'a' is a variable, not the address of
a variable
f<a>();
^ Compiler returned: 1