Let's say that
template <const char*>
struct A{};
const char a[] = "asd";
const char* p = "asd";
This description
A<a>{};
suitable for compiler. And this is understandable - the array adecays to a pointer to the first element. But if we create an instance awith the pfollowing
A<p>{};
the compiler gives an error message:
error: non-type char * 'type template argument is not a constant expression
Why doesn't the standard allow you to specify a named variable of a type const char*or just a string literal "asd", which is btw lvalue itself, as a template argument?
source
share