Working around the restriction in enable_shared_from_this
9 Aug
2011
9 Aug
'11
2:56 p.m.
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?
4842
Age (days ago)
4842
Last active (days ago)
0 comments
1 participants
participants (1)
-
kelvSYC