Re: templates, C++, and LNK2019

From: Jeff F (not_at_anywhere.com)
Date: 11/17/04


Date: Wed, 17 Nov 2004 11:18:09 -0500


"Bo Persson" <bop@gmb.dk> wrote in message
news:%23Cl7y9LzEHA.3908@TK2MSFTNGP12.phx.gbl...
>
> "Chris Burrger via .NET 247" <anonymous@dotnet247.com> skrev i
> meddelandet news:%23KcL3TIzEHA.1412@tk2msftngp13.phx.gbl...
> > I've found some other posts that deal with this linker error, but none
> > of those solutions work for me. I just got VS.NET 2003 and I wanted
> > to try it our with some basic algorithms. I am trying to make a singly
> > linked list, using templates.
> > I?ll post my code and then the error message at the end.
> > //////////Node.h
> > #ifndef __CSL_NODE
> > #define __CSL_NODE
> > namespace CSL {
> > template<typename T> class Node {
> > public:
> > Node( T nm );
> > Node( T nm, Node* n );
> > ~Node();
> > public:
> > T name; Node* next;
> > };
> > }
> > #endif
> >
> > /////////Node.cpp
> > #include "Node.h"
> > namespace CSL {
> > template<typename T>
> > Node<T>::Node( T nm ) {
> > name = nm; next = 0;
> > }
> > template<typename T>
> > Node<T>::Node( T nm, Node* n ) {
> > name = nm; next = n;
> > }
> > template<typename T>
> > Node<T>::~Node() {
> > }
> > }
>
>
> Separate compilation of template implementations are not supported by
> the compiler.
>
> Even if it was, you should have indicated that by using "export
> template" in the header file.
>
> As things are now, you just have to include the implementation in the
> header file!

Or you can explicitly instantiate for each of the desired types in the .cpp
file.

Jeff F