Advertisement Jump to content
Sign in to follow this  

stl::vector + refcounting goes wrong

This topic is 4933 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 class that is a handle to a refcounted object. When the class goes out of scope, it decreases the object's refcount. Upon being assigned another pointer the new object's refcount is increased (the previous object, if it exists, is released first). Now I have an stl::vector of these refhandles. If I push_back a refhandle, the object's refcount isn't being increased (nor is it being decreased when the vector goes out of scope). Is there any way of fixing this (for example with a custom allocator)? Maybe I'm going at this the wrong way... any suggestions? The offending code can be found at* For *, substitute "kbl/base/refcount.h" for the refhandle's code, or "kbl/gui/controls/container.h" for the vector's declaration (~ line 48; "typedef cRefHandle<cComponent> h_component_t;") Note that ".../kbl/kbl/..." should be in the URL (not a typo). Alternatively you could check out the latest revision using subversion. Thanks for any help and / or advice!

Share this post

Link to post
Share on other sites
Have you defined a copy constructor for your handle object?

class Name{


Name(const Name&); // copy constructor

STL uses the stored type's copy constructor; my guess is that you haven't defined one, and it is using a default copy constructor.

[Edited by - Verg on July 18, 2005 8:07:25 PM]

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!