I'm trying to make a templated node for a linked list but get error LNK2019: unresolved external symbol when I attempt to build the solution. This only happens when I try to create an instance of the Node in Main.
Node.h:
#ifndef Node_A
#define Node_A
template <class T>
class Node
{
public:
Node();
~Node();
T getData();
Node* getNext();
void setData(T);
void setNext(Node*);
private:
Node *next;
T data;
};
#endif
Node.cpp
#include "Node.h"
template <class T>
Node<T>::Node()
{
next = NULL;
return;
}
template <class T>
Node<T>::~Node()
{
return;
}
...irrelevant
Main.cpp
#include <iostream>
#include "Node.h"
using namespace std;
int main()
{
Node<int> a,b;
//Node<int> *ptr;
/*...*/
return 0;
}
Error Message:
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Node<int>::Node<int>(void)" (??0?$Node@H@@QAE@XZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Node<int>::~Node<int>(void)" (??1?$Node@H@@QAE@XZ) referenced in function _main