Not if you use shared ownership semantics.
Use std::shared_ptr to own the object, if available, else use boost::shared_ptr.
shared_ptr is reference counted. The destructor***SNIP - After clarification of the owned object will not be called until zero shared_ptrs owning that object remainscenario, I posted this answer in existence. Create your object:a comment originally ***
std::shared_ptr<Derived2> B = std::make_shared<Derived2>(); ThenHow about this can be copied as much as. In your stack, store unique_ptrs. When you wantpop from the stack, you grab the raw pointer from the unique_ptr and shove it into another unique_ptr - this second one is declared with a custom deleter which, on destruction, retains the actual object B points to will only be deleted once all those copied have gone outlocation of scopethe stack and performs the reverse of the pop operation. This will work with shared_ptr too but obviously it depends on what you need.
AnywayIt's independent of the type of B, go read up about shared_ptrand could be encapsulated entirely in the stack class (barring the unique_ptr+deleter type, there isbut that would just be a lot of cool stuff you can do with it and its buddy unique_ptrtypedef).