Hello all, I am having some trouble creating and using a template based linked list and I hope you all can help me out. I have created a LinkedList class, and I am trying to use it in my main, but I get a unresolved external link error, that I hope you all can help me with.
LinkedList.h
#pragma once
#include <iostream>
using namespace std;
template < class T >
class LinkedList{
private:
class ListNode{
public:
T value; // Node value
ListNode *next; // Next Node
ListNode ( T v, ListNode *n = NULL) : value( v ), next( n ) { }
}; // ListNode
ListNode *head;
public:
LinkedList ( ListNode *ptr = NULL ) { head = ptr; }
~LinkedList ( void );
void appendNode ( T object);
void insertNode ( T object);
void deleteNode ( T object);
void displayList ( void );
}; // LinkedList
LinkedList.cpp
#include "LinkedList.h"
template < class T >
void LinkedList<T>::appendNode( T object ){
ListNode *newNode = new ListNode( object ), *nodePtr;
if ( !head )
head = newNode;
else {
for ( nodePtr = head; nodePtr->next; nodePtr = nodePtr->next )
nodePtr->next = newNode;
}
}
I get the error in my main when I use the -> append, as so:
#include <iostream>
#include "LinkedList.h"
using namespace std;
int main(){
LinkedList<double> *myList = new LinkedList<double>;
myList->appendNode(45.67); //this is what gives me the error...
return 0;
}
Can you help me out? Thanks!