Re: templates, C++, and LNK2019

From: Bo Persson (bop_at_gmb.dk)
Date: 11/17/04


Date: Wed, 17 Nov 2004 17:06:52 +0100


"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!

Bo Persson