auto_ptrs should not be used in STL containers.
The C++ Standard says this should not even compile, but some compilers allow it. An auto_ptr object does not have value semantics, because when you copy it, it changes the source object.
When you store auto_ptrs in STL containers and manipulate them, temporaries are sometimes created. This causes the source auto_ptr to have its pointer set to null, and when the temporary is
deleted, it deletes the object that the auto_ptr points to. The Boost smart pointers are usable in STL containers.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment