Subject: Re: [boost] [shared_ptr] enable_shared_from_any ?
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-05-18 08:22:46
Philip Warner wrote:
> On 18/05/2010 10:33 AM, Frank Mori Hess wrote:
> from my original post:
> > Specifically, what I would like to see is a solution to the
> > following code:
> > C1 *p = new C1();
> > shared_ptr<C1> ptr(p);
> > ...
> > ...some time later....
> > shared_ptr<C1> ptr2<p>;
> > and the resulting mess because of double-deallocation.
> I am very happy to provide a patch that:
> - adds a class, enable_shared_from_any, that can be inherited from
> - updates shared_ptr to work in the above code, if C1 inherits from
> What we have at the moment is something like 'SafeSharedPtr' that
> inherits from 'shared_ptr' which does what I want, but which is less
> efficient than a native implementation would be
I don't see how inheriting from a special base class helps. Instantiating instances of a special type is no safer than calling a different function for this purpose. The issue is merely one of supplying external knowledge that the new shared_ptr should not assume sole ownership of the raw pointer. enable_shared_from_this was created to express a special use case of, as you point out, a more general need.
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.