Jump to content
  • Advertisement
Sign in to follow this  
BattleMetalChris

alternative to std::vector of auto_ptrs

This topic is 2696 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As we all know, you can't create a std::vector of auto_ptrs, due to them changing ownership of the pointee when they're copied. However, I have a function which needs to return some sort of reference to an object created with 'new' and I'd really rather use a smart pointer to do this. I then want to store a bunch of these in a vector. What's the best alternative to use, shared_ptr?

Share this post


Link to post
Share on other sites
Advertisement
In the new C++ standard (C++0x) auto_ptr has been deprecated. Instead you can use unique_ptr that can be used in a similar way as auto_ptr but has many improvements. One of them is that you can have them inside std::vector. So if your compiler support it I strongly recommend unique_ptr.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!