Здраствуйте, имеется цледующая проблема:
создан связанный цписок из Clients
при возврате из функции deQueue() теряется имя у Client
на сколько мне известно это происходит когда конструктор не переписывает имя, подскажите пожалуста в чем моя ошибка.
В данном примере для упрощения я проверяю случай когда в очереди имеется только один клиент
class Client
{
public:
Client();
Client(const char *name);
Client(const Client &cl);
~Client(){};
char *getName()const;
bool hasKit()const;
int kitNumber()const;
void receiveKit(Product kit);
Client *getNext()const;
void setNext(Client &cl);
void setNextNull();
void toString();
private:
char *_name;
Client *next;
Product *_kit;
};
//Copy constructor
Client::Client(const Client &cl)
{
_name=new char[strlen(cl._name)+1];
strcpy(_name, cl._name);
if(cl.hasKit()) //Checks if there is some kit in Client
_kit=new Product(cl.kitNumber());
else
_kit=NULL;
next=NULL;
}
//Destructor
Client::~Client()
{
delete [] _name;
_name=NULL;
delete _kit;
_kit=NULL;
}
class ClientQueue
{
public:
ClientQueue();
~ClientQueue();
bool addToLine(Client &cl);
Client deQueue();
int size()const;
bool isEmpty()const;
private:
Client *head; //Head of queue
Client *tail; //Tail of queue
};
//Default constructor
ClientQueue::ClientQueue()
{
head=NULL;
tail=NULL;
}
//Reurns Client from queue
Client ClientQueue::deQueue()
{
if(head==tail) //If there is only one Client in queue
{
return *head;
}
}
int main()
{
Client c1; //Create object of Client
ClientQueue q; //Create object of ClientQueue
q.addToLine(c1); //Adding client to queue
q.deQueue(); //Get Client from queue
//Когда проверяю через дебагер, возвращается клиент без имени
return 0;
}