I am trying to implement a singly linked list that stores multiple types of item. So I came across templates, but when I tried running the following code, the compiler gives me several linking errors (LNK 2019: unresolved external symbol). I haven't really done anything yet and can't figure out what went wrong. Can anyone please point out my mistake??
singlylinkedlist.h
template <class Item>
class SinglyLinkedList
{
public:
SinglyLinkedList();
~SinglyLinkedList();
private:
template <class I>
struct Node {
I item;
Node<I> *next;
};
Node<Item> *head;
};
singlylinkedlist.cpp
#include "singlylinkedlist.h"
template <class Item>
SinglyLinkedList<Item>::SinglyLinkedList()
{
head = NULL;
}
main.cpp
#include <iostream>
#include "singlylinkedlist.h"
using namespace std;
int main()
{
SinglyLinkedList<string> list;
}