explicit-instantiation: extern template declarationThere are two forms of explicit instantiation: an explicit instantiation definition and an explicit instantiation 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&);
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
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>&);