template <class Type>
const queueType<Type>& queueType<Type>::operator=(const queueType<Type>& q)
{
if (this != &q)
copyQueue(q);
return *this;
}
template <class Type>
void queueType<Type>::copyQueue(const queueType<Type>& queue)
{
delete [] list;
maxQueueSize = queue.maxQueueSize;
queueFront = queue.queueFront;
list = new Type[maxQueueSize];
for (int s = 0; s < maxQueueSize; s++)
list[s] = queue.list[s];
}
template <class Type>
void queueType<Type>::queueType(const queueType<Type>& queue)
{
list = NULL;
copyQueue(queue);
}
Here are the overloaded assignment operator, utility function to copy the data and a copy constructor. I'm guessing the culprit is in one of the above.
Other functions act as their name implies. Can get code for those if needed. Here's the output.
4 5 3998839 19 3998832
q2 elements:
Press any key to continue...
The question: why wasn't the queue from queue copied to q2 even though q2 was assigned to queue?
Oh, and another thing, what's with the junk numbers in the output? Looks like it's returning an address. Seems to react this way when I put a variable into the queue (like (y-4) for example).
Sorry, I didn't note this the first time: void queueType<Type>::queueType(const queueType<Type>& queue) Constructors don't have return type const queueType<Type>& queueType<Type>::operator=(const queueType<Type>& q) Shouldn't return a const reference (the idea is that you could do A = B = C = ...;)
In copyqueue I think that you need to copy queueRear and count too.
Also it seems weird that you increment Rear before adding the new element (so Rear starts in -1). So I used count to check for empty or full.
I tried out all those suggestions, to no avail. The constructor one struck me as odd since the compiler accepted it. Thanks for the suggestions, though.