Can't create two different queues using one template queue

I get an error on stringQueue.enqueue(name) and [code]stringQueue.dequeue(name) underneath "name". The error I get is "cannot convert argument 1 from string to int". I'm trying to make a program that takes 5 numbers and enqueues and dequeues them, then takes 5 strings and enqueues and dequeues. And then display them on the screen. Any help would be greatly appreciated. I need to use only one template for this code. Thanks.


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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
using namespace std;

template <class T, int MAX_ITEMS>

class Queue
{
private:
	T items[MAX_ITEMS];
	int front;
	int rear;
public: 
	Queue() { front = rear = MAX_ITEMS - 1; }
	~Queue() {}
	void makeEmpty() { front = rear = MAX_ITEMS - 1; }
	void enqueue(int item)
	{
		rear = ((rear + 1) % MAX_ITEMS);
		items[rear] = item;
	}
	void dequeue(int& item)
	{
		front = ((front + 1) % MAX_ITEMS);
		item = items[front];
	}
	bool isEmpty() { return (front == rear); }
	bool isFull() { return (rear + 1) % MAX_ITEMS == front; }
};



#include <iostream>
#include "Queue.h"

using namespace std;

const int MAX_ITEMS = 6;

int main()
{
	int item;
	string name;
	Queue <int, MAX_ITEMS> intQueue;
	Queue <string, MAX_ITEMS> stringQueue;

	cout << "Enter 5 integer values: \n";
	while (true)
	{
		if (intQueue.isFull())
			break;
		cin >> item;
		intQueue.enqueue(item);
	}

	while (!intQueue.isEmpty())
	{
		intQueue.dequeue(item);
		cout << item << " --> ";
	}
	cout << "NULL\n\n";

	cout << "Enter 5 string values: \n";
	while (true)
	{
		if (stringQueue.isFull())
			break;
		cin >> name;
		stringQueue.enqueue(name); //error here
	}

	while (!stringQueue.isEmpty())
	{
		stringQueue.dequeue(name); //error here
		cout << name << " --> ";
	}
	cout << "NULL\n\n";

	system("PAUSE");
	return 0;
}
Last edited on
paste the error, verbatim.

1
2
3
4
//void enqueue(int item)
//void dequeue(int& item)
void enqueue(T item)
void dequeue(T& item)
That fixed it, ne555. Thank you.
Topic archived. No new replies allowed.