Boost logo

Boost Users :

Subject: [Boost-users] [shared_ptr] Is it possible for a shared_ptr to hand over it ownership
From: Max (loadcom_at_[hidden])
Date: 2008-12-25 07:57:13


hello all

I hope this is not a stupid question.

Suppose I have a shared_ptr which is the only owner of the pointee.
I hope there is a way to hand over its ownership to another object
without rendering the pointee being deleted.

Or, if the answer is no, is there an alternative class that has
this feature?

The use case is like this:

B b;
{
shared_ptr p1(A()), p2(A());

b.GetOwnership(p1.HandOver());
// now p1 is empty
}
// p2 is deleted here

// but the A obj p1 used to be pointing to
// has been handed over to b and is still
// alive here

b.DestroyA();
// the A obj holded by b is destroyed by b
// explicitly

Thanks in advance
B/Rgds

Max

-------------------------------------------------------------------
ÐÂÀ˿ռ䡪¡ªÓëÅóÓÑ¿ªÐÄ·ÖÏíÍøÂçÐÂÉú»î£¡(http://space.sina.com.cn/ )


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net