Boost logo

Boost Users :

Subject: Re: [Boost-users] how to delete references to objects from a container...
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2009-12-09 09:35:19

rv_nath wrote:
> Hi forum members,
> I want to use boost's shared_ptr class for the connection pool class that i
> am writing. However, i have a requirement to delete the connection object
> (which is going to be the shared-ptr) explicitly based on certain checks
> like validity and expiry etc. If I store the shared_ptr, I want to know how
> to delete this explicitly from the stl container.
> According to my understanding shared_ptrs cannot be 'delete'd. So, how to
> achieve this...?

shared_ptr's CAN be deleted(or reset to NULL), you can NOT directly
delete the shared item that the shared_ptr is managing. When the last
shared_ptr referencing the shared item is deleted(or reset) it will
delete the shared item. There is also weak_ptr originally intended to
break cycles which may be of use to you. Otherwise your design will need
to communicate when to take appropriate actions.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at