Class Template problem

R

Russ Fink

References: said:
On Thu, 14 Oct 1999 16:37:25 -0700 in comp.lang.c++, KSG
I wanted to use a class template so I copied the matrix class verbatim
from the comp.lang.c++ FAQ [13.8]. It compiles fine.

But when I try to link it, it doesn't work.

With currently available C++ compilers, you have to put the entire
template source in the included header so the compiler can generate an
instance matching the template args you call for. Putting the template
in a different file and linking won't do it.

This is a reply to an old post, but in the interest of anyone that has
found this thread by searching through Google (or its equivalents),
this issue has existed for a very long time and is addressed in the
C++ FAQ-LITE maintained by Marshall Cline. Here is a link for all
eternity (or at least until Parashift is bought by Microsoft, its
business units carved up and sold off, and its projects off-shored):

http://www.parashift.com/c++-faq-lite/containers-and-templates.html#faq-34.12

The most simple solution is to put the entire template definition
(class decls, method code) in the header file.

Apologies to those who know this already.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top