Jump to content
  • Advertisement
Sign in to follow this  
BattleMetalChris

alternative to std::vector of auto_ptrs

This topic is 2777 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!