zeotherm wrote:
Patrick, I believe that you need to move the definition of you f()
function into the header file. Templates need to have their member
function defined in the header where the class is defined or you will
recieve a linker error (If I recall correctly).
You recall only half correctly: with most compilers you need to put
template definitions into header files if you use implicit
instantiation. However, he actually tries to do explicit instantiation
which removes the need of having the template definition in the header.
So move what is in foo.cpp into foo.h.
A better advice is: use the correct syntax for explicit instantiation!
Also, I am not sure what you are trying to
accomplish with the line "template Foo<int>;"...
This look much like an explicit instantiation but is not quite. The
correct syntax is this:
template class Foo<int>;
This instantiates all member of the class template 'Foo' with the
template parameter 'int'. After this instantiation, you can use
'Foo<int>' in all translation units without putting the definitions
of the member functions into a header. Of course, if you need 'Foo'
for other types, too, you either need to add appropriate
instantiations or make the definitions available for implicit
instantiation.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting