Date: Fri, 20 Dec 1996 10:15:49 GMT From: "C. N. Feng" Subject: undefined reference .... template To: DJGPP Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII 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 temp { public: temp(); ~temp(); private: DataT info; }; template temp::temp(){info=0;} template temp::~temp(){} #endif // TEMPLATE_H // **************** test.cc ********************************* #include"temp.h" temp itemp; /* If I declare itemp here, the error is test.o(.text+0x59):test.cc: undefined reference to `temp::temp(void)' make.exe: *** [test.exe] Error 1 */ int main(void) { //temp 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 $<