Hello Everyone,
I'm trying to implement a Polymorphic Queue.
Here is my trial:
QQueue <Request *> requests;
while(...)
{
QString line = QString::fromUtf8(client->readLine()).trimmed();
if(...)){
Request *request=new Request();
request->tcpMessage=line.toUtf8();
request->decodeFromTcpMessage(); //this initialize variables in request using tcpMessage
if(request->requestType==REQUEST_LOGIN){
LoginRequest loginRequest;
request=&loginRequest;
request->tcpMessage=line.toUtf8();
request->decodeFromTcpMessage();
requests.enqueue(request);
}
//Here pointers in "requests" do not point to objects I created above, and I noticed that their destructors are also called.
LoginRequest *loginRequest2=dynamic_cast<LoginRequest *>(requests.dequeue());
loginRequest2->decodeFromTcpMessage();
}
}
Unfortunately, I could not manage to make work Polymorphic Queue with this code because of the reason I mentioned in second comment.
I'm open to any improvement of my code or a new implementation of polymorphic queue.
Thanks.