www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/15/03:50:55

Date: Mon, 12 May 1997 23:47:21 +0200 (CEST)
From: matra <matra AT diemme DOT it>
To: Dennis Janssen <nessnaj AT worldonline DOT nl>
cc: djgpp AT delorie DOT com
Subject: Re: templates
In-Reply-To: <01bc5fc6$6d16b7e0$0b88099a@dennis.worldonline.nl>
Message-ID: <Pine.BSF.3.95q.970512234603.216A-100000@rook.matranet.org>
MIME-Version: 1.0


On 13 May 1997, Dennis Janssen wrote:

> Hi,
> 
> I'm new to C++ and now I'm trying to learn how to use templates.
> 
> I've written the following three files.
> 
> [CSTACK.H]
> #ifndef CSTACK_H
> #define CSTACK_H
> 
> template <class stackType>
> class cStack {
> public:
>   cStack();
>   int push(stackType element);
> };
> #endif CSTACK_H
> 
> [CSTACK.CC]
> #include <iostream.h>
> #include "cstack.h"
> 
> template<class stackType>
> cStack<stackType>::cStack()
> {
>   cout << "Constructed" << endl;
> };
> 
> template <class stackType>
> int cStack<stackType>::push(stackType element)
> {
>   cout << "Pushing..." << endl;
>   return 0;
> };

  template class cStack<int>;
  template class cStack<float>;

  [ .. all types u need to istantiate in the template .. ]

> 
> [TESTSTCK.CC]
> #include "cstack.h"
> 
> int main ()
> {
>   cStack<int> int_stack;
> 
>   int_stack.push(12);
> 
>   return 0;
> }
> 
> 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)
> 
> How do I fix this? I've read something in info about GCC neither supporting
> the Borland model nor the C/C++ frontend (or something) but I don't
> understand how to fix it. 
> 
> 	Dennis!
> 
> 

- Raw text -


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