Sign in to follow this  
thedevdan

containers and auto_ptr

Recommended Posts

I know that you shouldn't put auto_ptr-like smart-pointers in STL containers because the containers aren't gauranteed by the standard not to make internal copies (which would, of course, screw up whatever they are making internal copies of). Now, if I want destructive-copy smart-pointers (like auto_ptr), do I have to make my own containers!? Is there a way around this weirdness?

Share this post


Link to post
Share on other sites
What are you using them for? Maybe boost::shared_ptr would do the trick. It allows you to keep several shared pointers to an object and when all the pointers go out of scope the object gets deleted.

Share this post


Link to post
Share on other sites
Use boost::shared_ptr instead (since it was designed for just that purpose); IIRC it's set to be included in the C++ standard, so you'll be ahead of the curve.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why not just allocate an auto_ptr on the heap? ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this