delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/10/07:03:35

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: template header files
Date: Sun, 10 Sep 2000 11:45:22 +0100
Organization: Customer of Energis Squared
Lines: 29
Message-ID: <bgpmrs07v570gtuavvi16s5n050e58b1av@4ax.com>
References: <39BAE868 DOT B8948FF7 AT operamail DOT com>
NNTP-Posting-Host: modem-151.georgia.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: newsg4.svr.pol.co.uk 968582778 11416 62.137.61.151 (10 Sep 2000 10:46:18 GMT)
NNTP-Posting-Date: 10 Sep 2000 10:46:18 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Newsreader: Forte Agent 1.7/32.534
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Sahab Yazdani <sahaby AT operamail DOT com> wrote:

> hello i have written my own linked list template file and now want to
> use it as a library (you know in different executables, etc). the
> problem is that for every time that I write:
> 
> LinkedList<foo> bob;
> 
> the linker returns "undefined reference to LinkedList<foo>" and refuses
> to actually compile the code.  i have included as attachment the header
> file for the linked list, the actual code and a short sample program
> using this library (which obviously doesn't work..)

The simplest way to use templates is to put the implementation of the
class template in the header file, not in a separate source file.  

In your case that means cut and paste everything from linkedlist.cc
into linkedlist.h, and delete linkedlink.cc.

Or, if you prefer, #include "linkedlist.cc" from linkedlist.h.

You do not compile linkedlist.cc so there is no linkedlist.o to link
with.

> thank you in advance for any help you may provide.
> 
> PS.  Sorry if this isn't a DJGPP specific question...

I believe this is a C++ FAQ.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019