Код: Выделить всё
extern templateЯ ищу эквивалент для шаблонов переменных: объявите семейство переменных, используя шаблон, объявите, что некоторые из них созданы, а затем создайте их экземпляры в какой-либо единице перевода. Однако я не могу объявить шаблон переменной, не определив его одновременно.
Похоже, что следующее должно работать, но не работает (clang 19):
Код: Выделить всё
class A { public: A(int) {} };
extern template const A var;
extern template const A var;
template const A var = A(4);
Сообщения об ошибках:
Код: Выделить всё
:5:17: error: expected unqualified-id
5 | extern template const A var;
| ^
:7:25: error: explicit instantiation of 'var' does not refer to a function template, variable template, member function, member class, or static data member
7 | extern template const A var;
| ^
:9:21: error: no variable template matches specialization
9 | template const A var = A(4);
| ^
3 errors generated.
Compiler returned: 1
Подробнее здесь: https://stackoverflow.com/questions/793 ... -templates
Мобильная версия