title: Polymorphic Queue
body: <p>I'm trying to implement a Polymorphic Queue.
  Here is my trial:</p>
  
  <pre><code>QQueue &lt;Request *&gt; requests;
  
  while(...)
      {
          QString line = QString::fromUtf8(client-&gt;readLine()).trimmed();
  
          if(...)){                      
              Request *request=new Request();
              request-&gt;tcpMessage=line.toUtf8();
              request-&gt;decodeFromTcpMessage(); //this initialize variables in request using tcpMessage
              if(request-&gt;requestType==REQUEST_LOGIN){
                  LoginRequest loginRequest;
                  request=&amp;loginRequest;
                  request-&gt;tcpMessage=line.toUtf8();
                  request-&gt;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&lt;LoginRequest *&gt;(requests.dequeue());   
              loginRequest2-&gt;decodeFromTcpMessage();
          }
      }
  </code></pre>
  
  <p>Unfortunately, I could not manage to make work Polymorphic Queue with this code because of the reason I mentioned in second comment.I guess, I need to use smart-pointers, but how?
  I'm open to any improvement of my code or a new implementation of polymorphic queue.</p>
  
  <p>Thanks. </p>