Zdravim,
mam problem s nasledujucim kodom:
queuetp.h
template <class T, int n>
class QueueTP
{
private:
struct Node
{
T item;
Node * next;
};
Node * front;
Node * rear;
int items;
const int qsize;
QueueTP(const QueueTP & q) : qsize(0) {}
QueueTP & operator=(const QueueTP & q) {return * this;}
public:
explicit QueueTP();
~QueueTP();
bool isempty() const;
bool isfull() const;
int queuecount() const;
bool enqueue(const T & item);
bool dequeue(T & item);
};
template <class T, int n>
QueueTP<T, n>::QueueTP() : qsize(n)
{
front = rear = NULL;
items = 0;
}
template <class T, int n>
QueueTP<T, n>::~QueueTP()
{
Node * temp;
while (front != NULL)
{
temp = front;
front = temp->next;
delete temp;
}
}
template <class T, int n>
bool QueueTP<T, n>::isempty() const
{
return items == 0;
}
template <class T, int n>
bool QueueTP<T, n>::isfull() const
{
return items == qsize;
}
template <class T, int n>
int QueueTP<T, n>::queuecount() const
{
return items;
}
template <class T, int n>
bool QueueTP<T, n>::enqueue(const T & item)
{
if (isfull())
return false;
Node * add = new Node;
if (add == NULL)
return false;
add->item = item;
add->next = NULL;
items++;
if (front == NULL)
front = add;
else
rear->next = add;
rear = add;
return true;
}
template <class T, int n>
bool QueueTP<T, n>::dequeue(T & item)
{
if (front == NULL)
return false;
item = front->item;
items--;
Node * temp = front;
front = front->next;
delete temp;
if (items == 0)
rear = NULL;
return true;
}
wrkr.h
#include <iostream>
#include <cstring>
using namespace std;
class Worker
{
private:
char * fullName;
int id;
public:
Worker(const char * fn = "no name", const int n = 0);
Worker(const Worker & w);
~Worker();
Worker & operator=(const Worker & w);
void Show() const;
};
Worker::Worker(const char * fn, const int n)
{
fullName = new char[strlen(fn) + 1];
strcpy(fullName, fn);
id = n;
}
Worker::Worker(const Worker & w)
{
fullName = new char[strlen(w.fullName) + 1];
strcpy(fullName, w.fullName);
id = w.id;
}
Worker::~Worker()
{
delete [] fullName;
}
Worker & Worker::operator=(const Worker & w)
{
if (this == &w)
return *this;
delete [] fullName;
fullName = new char[strlen(w.fullName) + 1];
strcpy(fullName, w.fullName);
}
void Worker::Show() const
{
cout << "Meno pracovnika: " << fullName << endl
<< "ID pracovnika: " << id << endl;
}
workerqueue.cpp - viem ze by tam ten cyklus mal vyzerat inak ale o to teraz nejde
#include <iostream>
#include "queuetp.h"
#include "wrkr.h"
const int SIZE = 4;
const int AR_SIZE = 20;
int main()
{
QueueTP<Worker*, SIZE> workers; // ak by som tu dal parameter hodnotu (tj. len Worker) tak to funguje ale nechapem preco ma problem s ukazovatelom
char choice;
for (int i = 0; i < SIZE; i++)
{
cout << "p: pridat pracovnika, o: odobrat pracovnika, k: koniec\n";
char choice;
cin >> choice;
if (choice == 'k') break;
while (strchr("pok", choice) == NULL)
{
cout << "Zadajte p, o alebo k: ";
cin >> choice;
}
cin.get();
switch (choice)
{
case 'p':
{
char name[AR_SIZE];
int id;
cout << "Meno pracovinka: ";
cin.getline(name, AR_SIZE);
cout << "ID pracovnika: ";
cin >> id;
workers.enqueue(Worker(name, id));
break;
}
case 'o':
Worker temp;
workers.dequeue(temp);
temp.Show();
break;
}
}
return 0;
}
pri kompilacii vyprodukuje chybu:
workerqueue.cpp: In function ‘int main()’:
workerqueue.cpp:42: error: no matching function for call to ‘QueueTP<Worker*, 4>::enqueue(Worker)’
queuetp.h:68: note: candidates are: bool QueueTP<T, n>::enqueue(const T&) [with T = Worker*, int n = 4]
workerqueue.cpp:48: error: no matching function for call to ‘QueueTP<Worker*, 4>::dequeue(Worker&)’
queuetp.h:93: note: candidates are: bool QueueTP<T, n>::dequeue(T&) [with T = Worker*, int n = 4]
predom dakujem ze odpovede