I am trying to get a linked list, and here is my code
node.h
template<class Node_entry>
struct Node{
Node_entry entry;
Node<Node_entry> *next;
Node();
Node(Node_entry entry,Node<Node_entry>* add_on=NULL);
};
template<class Node_entry>
Node<Node_entry>::Node()
{
next=NULL;
}
template<class Node_entry>
Node<Node_entry>::Node(Node_entry item,Node<Node_entry>* add_on)
{
entry=item;
next=add_on;
}
Queue.h
#include "node.h"
enum Error_code{
success,overflow,underflow
};
template<class Queue_entry>
class Queue {
public:
Queue();
bool empty() const;
Error_code append(const Queue_entry &item);
Error_code serve();
Error_code retrieve(Queue_entry &item)const;
int size()const;
//Safety features for linked structures
~Queue();
Queue(const Queue<Queue_entry> &original);
void operator = (const Queue<Queue_entry> &original);
protected:
Node<Queue_entry> *front, *rear;
};
and then i got a problem in following code:
template<class Queue_entry>
Error_code Queue<Queue_entry>::append(const Queue_entry &item)
{
Node<Queue_entry> *new_rear=new Node(item);
if(new_rear==NULL) return overflow;
if(rear==NULL) front=rear=new_rear;
else{
rear->next=new_rear;
rear=new_rear;
}
return success;
}
The compiler turns out The code:
Node<Queue_entry> *new_rear=new Node(item);
error C2955: 'Node' : use of class template requires template argument list
<...>).