title: Destroying Class pointers with STL Queue pop()
body: <p>What happen when you get a pointer through <code>some_queue.front()</code>, assign it to another variable, and then call <code>some_queue.pop()</code>? Who is supposed to cleanup the memory? (I am using c++98, I can use boost smart pointers if really needed)</p>
  
  <p>Ex: (Why does this work? or is it not supposed to?)</p>
  
  <pre><code>class SClass {
  public:
      SClass(int si): sInt(si){}
      int getSInt(){ return sInt; }
  
  private:
      int sInt;
      ... // bunch of other complicated data types so copy might be slow
  };
  
  int main()
  {
     cout &lt;&lt; "Hello World" &lt;&lt; endl; 
     queue&lt;SClass *&gt; sq;
     for(int i = 0; i &lt; 10; i++){
         SClass *sc = new SClass(i);
         sq.push(sc);
     }
     SClass *s2 = NULL;
     while(!sq.empty()){
         s2 = sq.front();
         sq.pop();
         cout &lt;&lt; s2-&gt;getSInt() &lt;&lt; endl;
     }
     delete s2;
     return 0;
  }
  </code></pre>
  
  <p>Working test code here: <a href="http://cpp.sh/6z7ke" rel="nofollow">http://cpp.sh/6z7ke</a></p>