Okay, I'm making a project that implements a Double Linked List using classes, templates and structures. I constantly get the error:
doublelinklist.h(21) : error C2955: 'Node' : use of class template requires template argument list
when declaring the head and tail of a node in the LinkedList class.
DoubleLinkList.h:
#ifndef DOUBLELINKLIST_H
#define DOUBLELINKLIST_H
#ifndef NULL
#define NULL 0
#endif
//#include <stdio.h>
//#include <string>
template <class T>
struct Node
{
T val;
Node * next;
Node * prev; //both of these are self-referential data types/structures
};
template <class T>
class LinkedList
{
private:
static Node * head; //C2955
static Node * tail; //C2955
public:
bool push(T);
//bool pop();
//T at(); //C2146
//bool clear();
LinkedList()
{
/*static Node * */head = NULL;
/*static Node * */tail = NULL;
}
~LinkedList()
{}
};
#endif
DoubleLinkList.cpp
#include "DoubleLinkList.h"
template <class T>
bool LinkedList<T>::push(T pushMe)
{
Node * newN = new Node;
newN->next = NULL;
newN->prev = NULL;
if(this->head == NULL)
{
head = newN;
head->val = pushMe;
tail = newN;
printf("the value in the head is %d\n", head->val);
return true;
}
newN->prev = tail;
tail->next = newN;
newN->pushMe;
tail = newN;
printf("The value in the head is %d\n", head->val);
return true;
}
//bool LinkedList::pop(int remove_where)
//{
// Node * toRemove = at(remove_where);
//
// if(toRemove == head)
// {
// toRemove->next->prev = NULL;
// head = toRemove->next;
// }
//
// else if(toRemove = tail)
// {
// toRemove->prev->next = NULL;
// tail = toRemove->prev;
// }
//
// else
// {
// toRemove->prev->next = toRemove->next;
// toRemove->next->prev = toRemove->prev;
// }
//
// delete toRemove;
//
// return true;
//
//}
//
//T LinkedList::at()
//{
//
//
//}
//
//LinkedList::clear()
//{
//
//
//}
main.cpp
/*
1) Implement a Double-Linked List using templates and classes in C++.
You may use the STL type "List" as a reference.
A) Don't forget to implement a NODE class...
B) Don't forget to implement a class that is the actual list...
i) You need to have AT LEAST:
Push
Pop
At
Clear
2) Write a program that tests the functionality of your list class with the data types "int" and "std::string".
*/
#include <stdio.h>
#include <string>
#include "DoubleLinkList.h"
//template <class T>
int main()
{
int x = 5;
LinkedList<int> derp;
derp.push(x);
return 0;
}