I'll forewarn you, it is my first time posting on this site so If I do not adhere to proper etiquette, let me know so I can make future adjustments.
Anyhow, I have a program due Wednesday that is along the lines of the classic Bank Teller simulation using Queue's.
Unlike most of these programs, I have to integrate my own Queue, QueueNode, Teller, and Customer classes. I have attached all of these headers below plus the main file.
Now the error:
While I'm sure there are other issues with the code, it will not let me create a new customerQueue (of Queue type) object as such:
Queue<Customer> customerQueue;
The error it is giving me is:
1 2
no matching constructor for initialization of
'Queue<Customer>'
/*
* Queue2.h
*
* Created on: Feb 16, 2014
* Author: grantmcgovern
*/
#ifndef QUEUE2_H_
#define QUEUE2_H_
#include <iostream>
#include "Teller.h"
#include "Queue.h"
#include "Customer.h"
#include "QueueNode.h"
template <typename T>
class Queue
{
private:
conststaticint Q_SIZE = 10;
QueueNode<T>*front; // pointer to front of Queue
QueueNode<T>*rear; // pointer to rear of Queue
int count; // current number of items in Queue
constint qsize; // maximum number of items in Queue
// preemptive definitions to prevent public copying
Queue(T C)
{
qsize = 0;
rear = NULL;
front = NULL;
count = 0;
}
Queue & operator=(const T & q) {return *this;};
public:
~Queue()
{
QueueNode<T> * temp; // create temporary address store
while(front != (void *) 0) // while the queue is not empty
{
temp = front;
front =front->next; // advance the front object to the next
delete temp; // delete the temporary data
}
}
bool isempty() const
{
return count == 0;
}
bool isfull() const
{
return count == qsize;
}
int queuecount() const
{
return count;
}
bool enqueue(const T &data) // add item to end
{
if(isfull()) // if queue is full halt queuing
returnfalse;
QueueNode<T> *add = new QueueNode<T>; // create node
add->customer = data; // set node pointers
add->next = (void *) 0; // or nullptr;
count++;
if (front == (void *) 0) // 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
returntrue;
}
bool dequeue(T &data) // remove item from front
{
if(front == (void *) 0) // front node is empty, queue is empty
returnfalse;
data = front->customer; // set data to first item in queue
count--; // decrement item count
QueueNode<T>* temp = front; // save location of first item
front = front->next; // reset front to next item
delete temp; // delete former first item
if (count == 0) // if the queue is now empty set rear to point to nothing
rear = (void *)0;
returntrue;
}
};
#endif /* QUEUE_H_ */
You haven't defined a default constructor for Queue. Because you've defined another constructor (the private one), the compiler won't create a default one for you. You have to define it explicitly.