Я действительно не понимаю, почему приведенный ниже код не компилируется:
template<const char*>
struct Foo{};
constexpr const char s1[] = "test1";
constexpr const char* const s2 = "test2";
int main()
{
Foo<s1> foo1; // ok
// Foo<s2> foo2; // doesn't compile
}
Раскомментирование последней строки в main()
делает g++ и clang++ испускать ошибки
error: 's2' is not a valid template argument because 's2' is a variable, not the address of a variable
и
error: non-type template argument for template parameter of pointer type 'const char *' must have its address taken
соответственно.
Мои вопросы:
- Почему
s1
экземпляр ОК иs2
нет? - Есть ли нормальная ситуация, когда такой параметр шаблона указателя непигового типа используется?