On Wed, 2004-03-03 at 18:43, Justin Findlay wrote:
> On Wed, Mar 03, 2004 at 04:32:01PM -0700, Von Fugal wrote:
> > Here's a really simple example with the same problem I'm having. I must be
> > doing something wrong, and I would guess it's probably in the bag.cpp file.
> 
> I remember having problems also trying to do the same thing, but never
> actually got it resolved.  The hack I used was to define every
> function of the class template within the header file so that
> theoretically the compiler is then forced to instantiate the classes
> you use when it compiles your user program.

That's not a hack; that's the way it has to be.  I remember arguing with
the CS 240 TAs about this years ago.  Templates cannot be defined and
compiled in a .cpp file.  If they were, then the compiler would have to
produce object code supporting every possible permutation of type T
(objects), which is impossible.  If you check the STL library, you'll
find there is no .cpp files.  It's all in the headers.  Then when you
use the STL templates, the compiler has to generate object code for each
of the types that you use.

Thus all template classes and member functions must be defined in the
header file (the complete code, not the prototypes).

Michael


> 
> See:
> $ info gcc
> "C++ Extensions"->"Template Instantiation"
> 
> 
> Justin
> 
> ____________________
> BYU Unix Users Group 
> http://uug.byu.edu/
> ___________________________________________________________________
> List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
-- 
Michael Torrie <[EMAIL PROTECTED]>

____________________
BYU Unix Users Group 
http://uug.byu.edu/ 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to