Re: Undefined reference to '...'
>>>>> "Gonzalo" == Gonzalo A Diethelm <gonzo@ing.puc.cl> writes:
[Good advice on The Right Way to use templates]
Gonzalo> If your compiler supports explicit template instantiation
Gonzalo> with the standard 'template class MyClass<int>;' mechanism
Gonzalo> (as g++ appears to), then this is what I would do:
Gonzalo> 1. Put the class declaration in a header file by itself.
Gonzalo> 2. Put the class definition in a source file by itself.
Gonzalo> 3. Put the template instantiation at files where you actually
Gonzalo> use the template. Preferably, put them in a file just by
Gonzalo> themselves; this way, it is easier to control whether you
Gonzalo> have instantiated a template or not.
Gonzalo> 4. [...]
I agree. But sadly stock gcc/g++ 2.7.2 fails to instantiate correctly
unless the explicit instantiation is in the *same file* as the
definition.
Plenty of other posts in this thread have suggested what to do in this
situation.
--
Gilbert Laycock email: gtl1@mcs.le.ac.uk
Maths and Computer Science, http://www.mcs.le.ac.uk/~glaycock
Leicester University phone: (+44) 116 252 3902
--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org .
Trouble? e-mail to templin@bucknell.edu .
Reply to: