C ++ 11 Локальные статические значения не работают в качестве аргументов шаблоновC++

Программы на C++. Форум разработчиков
Anonymous
C ++ 11 Локальные статические значения не работают в качестве аргументов шаблонов

Сообщение Anonymous »

Я не могу использовать локальные статические значения в качестве аргументов шаблонов, в C ++ 11. Например: < /p>

Код: Выделить всё

#include 
using namespace std;

template 
void print() {
cout 
error: ‘myStr’ is not a valid template argument of type ‘const char*’ because ‘myStr’ has no linkage
< /code>
В Clang 3.4.1 ошибки кода с < /p>
candidate template ignored: invalid explicitly-specified argument for template parameter 'Str'
Both compilers were run with -std=c++11
A link to an online compiler where you can select one of many C++ compilers.
Note, moving myStr outside main compiles and runs as expected.
Note, I have looked at similar StackOverflow questions from before C ++ 11, и большинство указывает на то, что это должно быть разрешено в C ++ 11. Например, использование локальных классов с алгоритмами STL

Подробнее здесь: https://stackoverflow.com/questions/269 ... -arguments

Вернуться в «C++»