Many C++ compilers (g++ being one of them) has a real problem
when you declare and define template classes in different files.
The problem is that the compiler doesn't have the object code to
properly instantiate the template when it comes across a reference to it.
Try #include "adt.cpp" in your adt.h and see if it works.
Cheng
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Benjamin
> Vera-Tudela
> Sent: Friday, February 05, 1999 11:11 AM
> To: [EMAIL PROTECTED]
> Subject: Compilation problems !!!
>
>
> Hi all ...
>
> Hey, this could be a really stupid question, but I dont care, all I need
> is help please ...
>
> I have 3 files: adt.h, adt.cpp, and driver.cpp in my linux box.
> driver.cpp includes adt.h, and adt.cpp also includes adt.h.
> adt.cpp is the implementation of several data structures as C++ templates
> (i.e. template <TYPE> class List ... etc.) and adt.h is its definition
> file.
>
> inside driver.cpp i declare a variable of type List<rec> where rec is
> just a structure. The problem I am having is during compilation using g++.
> I have tried creating a different adt.h and adt.cpp files that are not
> 'templates' and it worked. But I would like to keep the d.s. as templates.
> Here's the output ... any clues??? Thanks
>
> g++ -g -c driver.cpp
> g++ -I. -I /usr/include -g -c adt.cpp
> g++ -g -o driver driver.o adt.o
> driver.o: In function `main':
> /u/mrbenji/tools/driver.cpp:13: undefined reference to
> `List<rec>::List(void)'
> /u/mrbenji/tools/driver.cpp:17: undefined reference to
> `List<rec>::Insert(int, r
> ec &)'
> /u/mrbenji/tools/driver.cpp:19: undefined reference to
> `List<rec>::~List(void)'
> /u/mrbenji/tools/driver.cpp:19: undefined reference to
> `List<rec>::~List(void)'
> *** Error code 1
> make: Fatal error: Command failed for target `driver'
>
> Benjamin S. Vera-Tudela
> Computer Sciences Dept., UT Austin
> http://www.cs.utexas.edu/users/mrbenji
>
> ---------------------------------------------------------------------------
> Send administrative requests to [EMAIL PROTECTED]
>
---------------------------------------------------------------------------
Send administrative requests to [EMAIL PROTECTED]