devxlogo

STL Containers Should Not Hold auto_ptr<> Members

STL Containers Should Not Hold auto_ptr<> Members

During reallocation, a container re-constructs its elements in a new memory location and destroys the original elements by invoking their destructor. Since the destructor of auto_ptr deletes its bound object, auto_ptr members are invalidated after a reallocation. For this reason, auto_ptr objects should not be stored in a container.

devx-admin

Share the Post: