explicit-instantiation: extern template declaration
template<class T> class Array { void mf(); };
template class Array<char>;
template void Array<int>::mf();
template<class T> void sort(Array<T>& v) { /* ... */ }
template void sort(Array<char>&); // argument is deduced here
namespace N {
template<class T> void f(T&) { }
}
template void N::f<int>(int&); — end example
template<typename T> T var = {};
template float var<float>; // OK, instantiated variable has type float
template int var<int[16]>[]; // OK, absence of major array bound is permitted
template int *var<int>; // error: instantiated variable has type int
template<typename T> auto av = T();
template int av<int>; // OK, variable with type int can be redeclared with type auto
template<typename T> auto f() {}
template void f<int>(); // error: function with deduced return type
// redeclared with non-deduced return type ([dcl.spec.auto])
— end example
namespace N {
template<class T> class Y { void mf() { } };
}
template class Y<int>; // error: class template Y not visible in the global namespace
using N::Y;
template class Y<int>; // error: explicit instantiation outside of the namespace of the template
template class N::Y<char*>; // OK: explicit instantiation in namespace N
template void N::Y<double>::mf(); // OK: explicit instantiation in namespace N
— end example
template<class T> class Array { /* ... */ };
template<class T> void sort(Array<T>& v) { /* ... */ }
// instantiate sort(Array<int>&) – template-argument deduced
template void sort<>(Array<int>&); — end example