Boost logo

Boost Users :

Subject: [Boost-users] Working around the restriction in enable_shared_from_this
From: kelvSYC (kelvsyc_at_[hidden])
Date: 2011-08-09 10:56:35


Suppose I have a class called Group, extending boost::enable_shared_from_this<Group>. Now suppose I have something like this:

class Foo {
    boost::shared_ptr<const Group> G;
public:
    Foo(const Group& G_) : G(G_.shared_from_this()) {}
};

This would totally barf if, among other things, G_ was allocated from the stack, say, since I don't have an owning shared_ptr instance. So, it would appear that, at the very least, if you were to allocate a Group on the stack, then you would need a shared_ptr with a null deleter to make use of Foo. This seems inconvenient to whoever may want to use Foo, so is there a way to change this so get around the shared_ptr instance restriction without changing Foo?


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