Jump to content
  • Advertisement
Sign in to follow this  
Axiverse

smart pointer questions

This topic is 4698 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

I have a question about smart pointers: What if you are passing a dereferenced object in an array? How do you tell the user not to use a smart pointer with that? And if you mix normal pointers with smart pointers, wouldn't it be confusing?

Share this post


Link to post
Share on other sites
Advertisement
Passing a dereferenced object shouldn't work, as there would be a type incompatibility. If you mean passing a pointer to an object in an array, then the smart pointer will probably try to delete it, and either crash the program or corrupt the heap. Don't do that.

This is one reason why smart pointers usually accept pointers as constructor arguments for explicit constructors and do not accept pointers as arguments to the assignment operator. When you can only initialize a smart pointer with a pointer at construction, it limits the amount of accidental damage you can do.

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!