stl::vector + refcounting goes wrong
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!
Have you defined a copy constructor for your handle object?
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement