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() {
}
}
///////SingleLinkedList.h
#ifndef __CSL_SINGLELINKEDLIST
#define __CSL_SINGLELINKEDLIST
#include "Node.h"
namespace CSL {
template<typename T>
class SingleLinkedList {
public:
SingleLinkedList();
~SingleLinkedList();
public:
void Add( T name );
void Remove( T name );
void Reverse();
void PrintOut();
private:
int length; Node<T> *root; Node<T> *rear;
};
}
#endif
////////SingleLinkedList.cpp
#include <string.h>
#include <stdio.h>
#include "Node.h"
#include "SingleLinkedList.h"
namespace CSL {
template<typename T>
SingleLinkedList<T>::SingleLinkedList(): length(0) {
root = 0; rear = 0;
}
template<typename T>
SingleLinkedList<T>::~SingleLinkedList() {
//for a shorter post
}
template<typename T>
void SingleLinkedList<T>::Add( T name ) {
//for a shorter post
}
template<typename T>
void SingleLinkedList<T>::Remove( T name ) {
//for a shorter post
}
template<typename T>
void SingleLinkedList<T>::Reverse() {
//for a shorter post
}
template<typename T>
void SingleLinkedList<T>::PrintOut() {
//for a shorter post
}
}
//// LibTest.cpp
#include "SingleLinkedList.h"
#include "Node.h"
using namespace CSL;
int main(int argc, char* argv[]) {
SingleLinkedList<int> sll; //LNK2019 error
sll.Add( 1 );
sll.Add( 10 );
sll.Add( 5 );
sll.PrintOut();
//now rev
sll.Reverse();
sll.PrintOut();
//now add
sll.Add( 200 );
sll.Reverse();
sll.PrintOut();
return 0;
}
I get 5 LNK2019 errors when I try to compile, here is the first one:
LibTest error LNK2019: unresolved external symbol "public: __thiscall CSL::SingleLinkedList<int>::~SingleLinkedList<int>(void)" (??1?$SingleLinkedList@H@CSL@@QAE@XZ) referenced in function _main
Any help would be appreciated.
Thanks!
--------------------------------
From: Chris Burrger
-----------------------
Posted by a user from .NET 247 (
http://www.dotnet247.com/)