A template specialization can be explicitly declared as a way to suppress multiple instantiations. For example:
#include "MyVector.h"
extern template class MyVector<int>; // Suppresses implicit instantiation below --
// MyVector<int> will be explicitly instantiated elsewhere
void foo(MyVector<int>& v)
{
// use the vector in here
}
The “elsewhere” might look something like this:
#include "MyVector.h"
template class MyVector<int>; // Make MyVector available to clients (e.g., of the shared library
This is basically a way of avoiding significant redundant work by the compiler and linker.