22 Jun 2007, 01:32

Funky Visual Studio 2005 bug

I ran into this today with VS2005 SP1: if you define the body of a specialization of a template class’ member function in a separate cpp file, the linker will barf:


`template<class T> struct A { void f() {} };template<> void A::f(); // body in a separate cpp


You have to define the body in all source files (or at least one) that actually use the specialization of that function, normally in the header file:


`template<class T> struct A { void f() {} };template<> void A::f() { }


Not sure if I have explained correctly, but I hope you get the idea.