Sign in to follow this  

stl::vector + refcounting goes wrong

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

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