Mail Archives: djgpp/1995/03/17/03:03:47
As I see, more people got the problem with templates I solved a few weeks
ago, so I'll post it here:
Problem:
> I am trying to use a List template class and I keep getting:
>
> "undefined reference List<int>::Insert()"
> "undefined reference List<int>::First()"
>
> ...and so on for every List function that is called in my client
> program.
>
> I am using my own list implementation (not the one included with DJGPP).
> I have my List template class declaration in my header file (list.h) and
> the implementation in my list.cc file. My client program is in its
> separate file (intlist.cc).
Explanation / Solution:
If you compile list.cc, gcc can't know what type of instantiation you may be
need in future, so list.o doesn't hold the code for List<int> you need. To
do this add a line
template class List<int>;
to your file list.cc. This creates the code needed in list.o.
See chapter 7.5 in the gcc-manual! I'm going the way described at Page 165,
Point 3 and build a template-library of all my template-classes ever needed.
Hope this helps,
Roland
+---------------------------------------+---------------------------+
I Roland Exler I EMAIL: I
I Universitaet Linz I R DOT Exler AT jk DOT uni-linz DOT ac DOT at I
I Institut fuer Elektrische Messtechnik I I
I Altenbergerstr. 69 I Phone: I
I A-4040 Linz, AUSTRIA I + 43 732 2468 9205 I
+---------------------------------------+---------------------------+
- Raw text -