Jump to content
  • Advertisement
Sign in to follow this  
Kurioes

stl::vector + refcounting goes wrong

This topic is 4870 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 http://king0r.dyndns.org/svn/kbl/* 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
Advertisement
Have you defined a copy constructor for your handle object?


class Name{

public:

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 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!