delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/14/14:32:55

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.lang.c++,comp.os.msdos.djgpp,gnu.g++.help
Subject: Re: templates
Date: Wed, 14 May 1997 10:04:04 -0700
Organization: Alcyone Systems
Lines: 33
Message-ID: <3379F084.6C917A8B@alcyone.com>
References: <01bc5fc6$6d16b7e0$0b88099a AT dennis DOT worldonline DOT nl>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Dennis Janssen wrote:

> When I try to compile it using DJGPP 2.01 (based on gcc 2.7.0.1) I think
> I
> get the following two errors:
> 
> undefined reference to cStack<int>::cStack(void)
> undefined reference to cStack<int>::push(int)

It's because at link time it can't find the references to your template
class.  Remember that templates act like macros, and as such, have to be
available at compile time, not link time.  Change 

    #include "cstack.h"

to 

    #include "cstack.cc"

and it should work.

If it doesn't, you'll have to explicitly instantiate the class, using
something of the form 

    class cStack<int>;

-- 
       Erik Max Francis, &tSftDotIotE / email / max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
                      "The future / is right there."
                                 / Bill Moyers

- Raw text -


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