 <p>You have <a href="http://en.wikipedia.org/wiki/Object_slicing" rel="nofollow">slicing</a>:</p> <p>You should use <code>std::stack&lt;Z*&gt;</code> or <code>std::stack&lt;std::unique_ptr&lt;Z&gt;&gt;</code>.</p>