I am attempting to program a doubly linked list template. My program is setup with the class node defined in a header file,the list itself in a header file and finally the main in a separate cpp file which calls the list header. The list header calls the node header. The error I am receiving is
"dbList<int>::dbList(int, Node<int>*, Node<int>*)", referenced from:
_main in dbList.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Here is the code below:
template<class dtype>
class Node
{
public:
int position;
dtype data;
Node<dtype>* next;
Node<dtype>* prev;
Node( dtype data, Node<dtype>* next=0, Node<dtype>* prev=0);
};
#include "dbNode.h"
#include<iostream>
using namespace std;
template <typename Type>
class dbList
{
private:
int size;
Node<Type>* head;
Node<Type>* tail;
public:
dbList(int size=0,Node<Type>* head=0,Node<Type>* tail=0);
void insertNode(Type v);
void insertNode(Type v, int pos);
void displayList();
void tester();
};
template <typename Type>
void dbList<Type>::insertNode(Type v)
{
Node<Type>* tempa;
Node<Type>* tempb;
Node<Type>* tempc;
tempa->data=v;
if(this->head==0)
{
this ->head = tempa;
this ->head ->next = 0;
this ->head ->prev = 0;
this ->size++;
this ->head->position=size;
}
else
{
tempb = this ->head;
if(tempb ->next == 0)
{
tempa->next = tempb->next;
tempa ->prev = tempb;
tempb ->next = tempa;
this ->tail = tempa;
this ->size++;
this ->tail->position=size;
}
else
{
tempc = this ->tail;
tempa ->next = tempc ->next;
tempa ->prev = tempc;
tempc ->next = tempa;
this ->tail = tempa;
this ->size++;
tempc->position=size;
}
}
}
template<typename Type>
void dbList<Type>::displayList()
{
Node<Type> *tempa;
tempa = this ->head;
if(tempa == 0)
{
cout<<"This list is empty";
}
else
{
cout<<"List- ";
while(tempa != 0)
{
cout<< tempa -> data;
cout<< " ";
tempa = tempa -> next;
}
cout<< "\n";
}
}
template<typename Type>
void dbList<Type>::tester()
{
int selection;
Type tempa;
cout << "What would you like to do\n";
cout << "1. Insert Item\n"<<"2.Print List\n";
cin>>selection;
cout<<"\n";
switch(selection)
{
case 1:cout<<"What value would you like to add?";
cin>>tempa;
cout<<"\n";
insertNode(tempa);
break;
case 2:dbList<Type>::displayList();
break;
}
}
#include"dbList.h"
#include <iostream>
using namespace std;
int main ()
{
dbList<int> intlist;
intlist.tester();
}
This is my first time using templates. Please point out anything that does not make sense at all. I've been going through "C++ Templates the complete guide" , but it really is not very clear to me in some spots. So any help would be greatly appreciated. Thank you for your time.