Queue not compiling, seems to be related to the template type I'm using

Trying to write a simple linked-list queue. It worked before I split it into a header and a cpp file. I'm recently getting back to programming (in cpp) and I must have the syntax for this wrong somewhere. Any help is appreciated!

Header file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#ifndef QUEUE_H
#define QUEUE_H
#ifndef NULL
#define NULL 0
//implement a Queue using linked nodes
using namespace std;

template <typename ItemType>

class Queue //holds items in a first-in, first out linked list
{
private:
	//Nodes are the basic element in the queue, holding an item and a pointer to the next item
	struct Node { 
		ItemType item;
		Node* next;
	};	
	Node* head;
	Node* tail;

public:
	Queue():head(NULL),tail(NULL){}
	
	bool isEmpty(); //returns true if Queue is empty, false if not
	void add(const ItemType& item); //adds an item to the queue is the last position
	ItemType remove(); //removes an item from the queue and dereferences the pointer
	~Queue();
};


#endif
#endif 


.cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "Queue.h"

bool Queue::isEmpty(){
	return head == NULL;
}

void Queue::add(const ItemType& item) {
	Node* n = new Node();
	n->item = item;
	if(isEmpty())
		head = n;
	else
		tail->next=n;
	tail = n;
}

ItemType Queue::remove() {
	Node* n = head;
	ItemType item = n->item;
	head = head->next;
	delete n;
	return item;
}

Queue::~Queue() {
	while(!isEmpty()) remove();
}


Here's what the compiler tells me:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Queue.cpp:3:6: error: ‘template<class ItemType> class Queue’ used without template parameters
Queue.cpp: In function ‘bool isEmpty()’:
Queue.cpp:4:9: error: ‘head’ was not declared in this scope
Queue.cpp: At global scope:
Queue.cpp:7:6: error: ‘template<class ItemType> class Queue’ used without template parameters
Queue.cpp:7:23: error: ‘ItemType’ does not name a type
Queue.cpp:7:33: error: ISO C++ forbids declaration of ‘item’ with no type [-fpermissive]
Queue.cpp: In function ‘void add(const int&)’:
Queue.cpp:8:2: error: ‘Node’ was not declared in this scope
Queue.cpp:8:8: error: ‘n’ was not declared in this scope
Queue.cpp:8:16: error: expected type-specifier before ‘Node’
Queue.cpp:8:16: error: expected ‘;’ before ‘Node’
Queue.cpp:11:3: error: ‘head’ was not declared in this scope
Queue.cpp:13:3: error: ‘tail’ was not declared in this scope
Queue.cpp:14:2: error: ‘tail’ was not declared in this scope
Queue.cpp: At global scope:
Queue.cpp:17:1: error: ‘ItemType’ does not name a type
Queue.cpp:25:1: error: invalid use of template-name ‘Queue’ without an argument list


It looks like my Queue class just isn't being defined for some reason. I've just spent a lot of time trying to figure out why and I can't figure it out.
Any help is appreciated!
Topic archived. No new replies allowed.