Sign in to follow this  

Refering to Unique Pointer's Content

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

Hey forum!

 

I want to create a data structure that simply refers to the location of unique pointers.

 

While I could use shared pointers, it feels like an overkill.

At the moment, I use raw pointers for this case, leaving me with a bad taste.

 

The data structures I use:

-A vector of unique pointers to a game element

-Data structures of raw pointers to parts of that vector

 

Changing my game elements to shared pointer just that I can refer to them feels a bit overkill.

But maybe I'm all wrong.

 

Are there any other ways of dealing with this?

Share this post


Link to post
Share on other sites
I don't see anything particularly wrong with using raw pointers, as long as you can be sure that the object will exist for as long as you need it to.

In some cases I find that it's preferable to use indices to the array that owns the objects (you can give these indices their own type, like GameObjectID). But I don't think this going to be particularly useful in this case.

Share this post


Link to post
Share on other sites

tl;dr third post, but if you're taking pointers to vector members you better not add anything new to the vector.

 

Nvm, you're talking about getting the addresses from the u_ps in the vector, which is fine, provided that you can guarantee that the lifetime of the u_ps exceeds that of the raw pointers.

 

Also, just to make sure, is it a vector of pointers because of polymorphism?

Edited by Khatharr

Share this post


Link to post
Share on other sites

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

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