0

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

2
  • 1
    Sounds pretty self-explanatory. It's telling you forgot to supply a template argument list (i.e. something of the form <...>). Commented Dec 29, 2013 at 12:04
  • Thank you! Could you tell me how can i change my code to make it runable? I have some problems in dong this . Commented Dec 29, 2013 at 12:13

1 Answer 1

1

You forgot the template parameter in the second use of Node. The line in question should read

Node<Queue_entry> *new_rear=new Node<Queue_entry>(item);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.