class Queue with customers

template < class DT >
void Queue<DT>:: enqueue ( const DT &newDataItem )
throw ( logic_error )

// Inserts newElement at the rear of a queue.

{
QueueNode<DT> *p; // Pointer to enqueued data item

//make p a new QueueNode that has newDataItem and link of zero
p = new QueueNode(newDataItem, 0);

//If there are no nodes, set the front to be this new node
if ( p ==0 )
{
front = new;
}

//Otherwise, add the new node to the end
else
{
appendNode(newDataItem);
}

//Reassign the rear to p
rear = p;
}
*/these are the errors i need help with*/
d:\queuelnk.cpp(58) : error C2955: 'QueueNode' : use of class template requires template argument list
d:\queuelnk.h(19) : see declaration of 'QueueNode'
c:\program files\microsoft visual studio\vc98\include\xstring(79) : while compiling class-template member function 'void __thiscall Queue<int>::enqueue(const int &)'
d:\queuelnk.cpp(58) : error C2955: 'QueueNode' : use of class template requires template argument list
d:\queuelnk.h(19) : see declaration of 'QueueNode'
c:\program files\microsoft visual studio\vc98\include\xstring(79) : while compiling class-template member function 'void __thiscall Queue<int>::enqueue(const int &)'
d:\queuelnk.cpp(58) : error C2514: 'QueueNode' : class has no constructors
d:\queuelnk.h(19) : see declaration of 'QueueNode'
c:\program files\microsoft visual studio\vc98\include\xstring(79) : while compiling class-template member function 'void __thiscall Queue<int>::enqueue(const int &)'
d:\queuelnk.cpp(63) : error C2059: syntax error : ';'
c:\program files\microsoft visual studio\vc98\include\xstring(79) : while compiling class-template member function 'void __thiscall Queue<int>::enqueue(const int &)'
d:\queuelnk.cpp(64) : error C2143: syntax error : missing ';' before '}'
c:\program files\microsoft visual studio\vc98\include\xstring(79) : while compiling class-template member function 'void __thiscall Queue<int>::enqueue(const int &)'
d:\queuelnk.cpp(64) : error C2143: syntax error : missing ';' before '}'
closed account (zb0S216C)
ledzepdoors1 wrote:
p = new QueueNode(newDataItem, 0); (sic)
QueueNode needs < DT > immediately after it.

Wazzak
Thank you, now that simply I did not see lol. I'm still having errors with this function tho. I believe it may be the rest of the implementation but I'm not quite sure. I'm new with queues and stacks and still in the basis of learning.
closed account (zb0S216C)
Errors wrote:
'QueueNode' : class has no constructors (sic)

You need to give QueueNode a constructor that accepts a DT object and a pointer/int object. By looking at the error, it's telling me that QueueNode doesn't have a constructor that accepts the arguments you gave to it. The error is misleading since all structures have a constructor and destructor, regardless (the compiler adds them implicitly if no user-defined constructors are made).

Wazzak
Last edited on
[small]
template < class DT >
void Queue<DT>:: enqueue ( const DT &newDataItem )
throw ( logic_error )

// Inserts newElement at the rear of a queue.

{
QueueNode<DT> *p; // Pointer to enqueued data item
//make p a new QueueNode that has newDataItem and link of zero
p = new QueueNode<DT> (newDataItem, 0);
//If there are no nodes, set the front to be this new node
p -> info = newDataItem;
P -> next = NULL;
if(rear == NULL)
{
front = p;
}
//Otherwise, add the new node to the end
else
{
rear -> next = p;
}
//Reassign the rear to p
rear = p;

}


ok now thats what i changed it to. And in the header file it does show that.
|
|
|
V

class Queue;

template < class DT >
class QueueNode // Facilitator class for the Queue class
{
private:

// Constructor
QueueNode ( const DT &nodeData, QueueNode *nextPtr );

// Data members
DT dataItem; // Queue data item
QueueNode *next; // Pointer to the next element

friend class Queue<DT>;
};
[/small]
closed account (zb0S216C)
So what's the issue now? It compiles just fine with VC++ (I had to create a dummy Queue class to get it compile).

Wazzak
Ive tried it out and it works. I guess from maybe trying it too many times and the same error just reoccurring. well the problem im having is that info is not part of the class QueueNode. And I have no idea how to dequeue in main.
Last edited on
Never mind I keep making simple mistakes don't reply to the class thing I said lol. Anyway, I'm going to be working on my main now. I'm like I said earlier just not sure exactly how, but I will try it. This is a whole class with Queue and QueueNode for customers in a calling center. All I have left to do now is to dequeue the customer in main and allow timeArrived to be the returned value. Calculate the waitTime, totalWait, averageWait and maxWait. Any hints I would surely appreciate it. Thank you.
Topic archived. No new replies allowed.