I've made a class template called Queue but I'm having problems trying to instanciate it with a pointer to another class called Worker as the type. Queue<Worker*>
The problem I think comes with this concrete Queue method:
// Add item to queue
template <typename Type>
bool Queue<Type>::enqueue(const Type& item)
{
if (isfull())
return false;
Node* add = new Node; // create node
// on failure, new throws std::bad_alloc exception
add->item = item; // set node pointers (shallow copying!!!!!)
add->next = nullptr;
items++;
if (front == nullptr) // if queue is empty,
front = add; // place item at front
else
rear->next = add; // else place at rear
rear = add; // have rear point to new node
return true;
}
In the case of the type parameter being a pointer I need to copy the pointed-to value, not the address (I'm using dynamic memory management) to avoid the program crashing.
I don't know how to solve this with a template.
Any help?