Possible Duplicate:
Is there a bug with extern template in Visual C++?
I use something like that in VS12 in a *.cpp file
extern template class std::vector<int>;
... at some point here I need to instantiate vector on int
std::vector<int> v1; // would not expect this to be instantiated here as I already have a *.cpp where I instantiate this *only once* for all project uses
In a separate *.cpp I want to instantiate all commonly used template instances
#include "stdafx.h"
template class std::vector<int>;
template class std::list<int>;
template class std::list<long>;
template class std::list<short>;
template class std::list<long long>;
template class std::list<unsigned int>;
The way I know vector is instantiated in first *.cpp file also is because I get same compile times with extern declaration as without it(I actually declare extern more types so I can be sure timings are large enough to see the difference)
Question: Why it does not instantiate std::vector only in the separate *.cpp file ?
EDIT If in the same *.cpp file I have
extern template class std::list<int>;
void somefunc()
{
std::list<int> v1;
}
I do not get a liker error even if I don't explicitly instantiate std::list in a different cpp file. This could explain the fact that actually that gets instantiated even if I specify extern. Wonder why is that. I want to instantiate std::list in a single point.