Jump to content
  • Advertisement
Sign in to follow this  
ill

Any way to have C++ STL list not call destructor when removing value?

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

Yeah so I'm making a drawList kind of thing that all objects that are drawable, add themselves to this list each frame. The list handles sorting of the objects in proper draw order by depth which is why I'm using the STL linked list. Only problem is whenever the list has a value removed from it, the documentation says it always calls the object's destructor which I don't want. Like when it iterates through the draw list it should clear itself but not call the destructors of the things stored in the list since that would destroy those game objects. Is there a way to have the List do this withot calling destructors or do I have to make my own Linked List which I basically know how to do since I had to make it in Java, C, all that crap in all the classes I've been in.

Share this post


Link to post
Share on other sites
Advertisement
Don't add the actual object to the list then, just a pointer. Also, why clear and add everything each frame? Just resort the list itself.

Share this post


Link to post
Share on other sites
Quote:
Original post by ill
Only problem is whenever the list has a value removed from it, the documentation says it always calls the object's destructor which I don't want. Like when it iterates through the draw list it should clear itself but not call the destructors of the things stored in the list since that would destroy those game objects.


It would destroy the copies that you put into the draw list.

If that causes problems for the copied-from objects, then there is something wrong with either your copying process or your destruction process.

If your game objects store raw pointers to some kind of allocated resources, for example, consider instead using smart pointers.

Share this post


Link to post
Share on other sites
Funny thing is I thought of this as well over the course of the day. At the time I was coding it I was tired and didn't realize that storing just the pointer would not cause the original object to get destroyed.

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!