[vault] ctor_shared_from_this()

I've had a few cases where my design required calling shared_from_this() in a constructor and destructor. I made some modifications to enable_shared_from_this which I have posted here: http://www.boost-consulting.com/vault/index.php?order=rating&direction=1&directory=Memory There is a test function in a test file in the zip archive that will fail if you call shared_from_this() instead of my ctor_shared_from_this() method. Rob

On Sunday 23 December 2007 11:12, Robert Sitton wrote:
I've had a few cases where my design required calling shared_from_this() in a constructor and destructor. I made some modifications to enable_shared_from_this which I have posted here:
http://www.boost-consulting.com/vault/index.php?order=rating&direction=1 &directory=Memory
There is a test function in a test file in the zip archive that will fail if you call shared_from_this() instead of my ctor_shared_from_this() method.
But it just creates a shared_ptr with a null deleter in the constructor. I don't see how it adds anything over just using a raw pointer, since the shared_ptr in the constructor will have no relation to the external shared_ptr which will actually own the object after it is constructed. To do that, you would need to something along the lines of storing a copy of the shared_ptr inside the object until it is passed over to an external shared_ptr that really owns the object. Or, use a post-constructor and get the shared_ptr there, which is what I tried to support with deconstruct_ptr/postconstructible: http://www.comedi.org/projects/thread_safe_signals/libs/thread_safe_signals/... -- Frank
participants (2)
-
Frank Mori Hess
-
Robert Sitton