www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/22/08:35:15

Date: Sun, 22 Dec 1996 12:48:56 GMT
From: "Feng, Cheng-Ning" <fengcn AT essex DOT ac DOT uk>
Subject: Re: undefined reference .... template
To: Carlos Alberto Rega Liste <farega AT usc DOT es>
Cc: DJGPP <djgpp AT delorie DOT com>
Message-Id: <ECS9612221256B@essex.ac.uk>
Mime-Version: 1.0



On Fri, 20 Dec 1996 15:35:17 +0100 Carlos Alberto Rega Liste wrote:

> At 10:15 20/12/96 GMT, you wrote:
> >Hi,
> >
> >I am learning how to use template. However, I got the following problem
> > as stated in the code.
> >At the moment, the work around I found is to put the object of template 
> >into another "class" and an object of that "class" into the main function.
> >I am not sure whether there is another way to do it if I have to put
> >the object of template ouside the main function.
> >
> >Thanks
> >
> >Feng, Cheng-Ning
> >
> >// ***************** temp.h *******************************
> >#ifndef TEMPLATE_H
> >#define TEMPLATE_H
> >
> >template<class DataT> class temp
> >{       public:
> >        temp();
> >        ~temp();
> >
> >        private:
> >        DataT info;
> >};
> >
> >template<class DataT> temp<DataT>::temp(){info=0;}
> >template<class DataT> temp<DataT>::~temp(){}
> >
> >#endif // TEMPLATE_H
> >
> >// **************** test.cc *********************************
> >#include"temp.h"
> >
> >temp<int> itemp;
> >/*      If I declare itemp here, the error is
> >test.o(.text+0x59):test.cc: undefined reference to `temp<int>::temp(void)'
> >make.exe: *** [test.exe] Error 1
> >*/
> >
> >int main(void)
> >{       //temp<int> itemp;
> >        /*
> >        if I declare inside the main function, there is no error
> >        */
> >        return 0;
> >}
> >
> >// ********** The makefile *************************************
> >cc = gcc
> >flags = -Wall -O2 -m486 -s
> >links = -liostr
> >
> >execute = test.exe
> >
> >cc_sources = test.cc
> >
> >objects = $(cc_sources:.cc=.o)
> >
> >$(execute):$(objects)
> >        $(cc) $(flags) -o $@ $(objects) $(links)
> >
> >%.o:%.cc
> >        $(cc) $(flags) -c $<
> >
>         Hi. I had the same problem with templates and I fixed it by adding
> -fno-implicit-templates to the command line of gcc. I hope it can help you.
> 

Thanks for your reply. However, it is still not work.
But I found another way. In the code above, I made all the definitions as inline functions. 
It compiles and links ok.

Thanks

Feng, Cheng-Ning


- Raw text -


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