You are right that the object file you create from TemplateTester.cpp
will contain a symbol for the specialization you provided. This is the case because any explicit specialization causes the template to be instantiated, and it is doubly the case because you even added an explicit instantiation (which is actually unnecessary).
However, at the time when driver.cpp
is compiled, the compiler does not know about the specialization, because you only include TemplateTester.h
, and the specialization isn't mentioned there. So the compiler instantiates the template, of course not using the specialized definition, so you get your problem.
The Standard says (Italics by me):
(§14.7.3/6) If a template, a member template or a member of a class template is explicitly specialized then that specialization shall be declared before the first use of that specialization that would cause an implicit instantiation to take place, in every translation unit in which such a use occurs; no diagnostic is required. If the program does not provide a definition for an explicit specialization and either the specialization is used in a way that would cause an implicit instantiation to take place or the member is a virtual member function, the program is ill-formed, no diagnostic required. An implicit instantiation is never generated for an explicit specialization that is declared but not defined. [...]
So you need to make both, the declaration and the definition of the specialization known to the compiler when it works on driver.cpp
. The best way of doing this is by adding the entire specialization to TemplateTester.h
.
Note, again, that an explicit instantiation is not actually required.