 <p>The way your code looks like now, you shouldn't get a warning since <code>myclass</code> and <code>myClassList</code> have the same lifetime. However, if <code>myClassList</code> outlives <code>myclass</code>, you need to dynamically allocate <code>MyClass</code>:</p> <pre><code>vector&lt;MyClass*&gt; myClassList; { MyClass* myclass = new MyClass; myClassList.push_back(myclass); } </code></pre> <p>If the following is closer to what you actually have:</p> <pre><code>vector&lt;MyClass*&gt; myClassList; { MyClass myclass; myClassList.push_back(&amp;myclass); } </code></pre> <p>then <code>myclass</code> is destroyed at the closing <code>}</code>, and <code>myClassList</code> will contain a pointer to released memory.</p> <p>Also, is <code>MyClass</code> polymorphic? Do you really need to store pointers in the vector?</p>