Re: [Boost-users] enable_shared_from_this()
Frank Mori Hess
That means throwing exceptions from the constructor after using shared_from_raw (or in any derived constructor since ithe derived constructor would be called later) causes bad things to happen. That's no different from stashing away a raw pointer from a constructor (e.g. passing it as a "parent" pointer to a referenced object). But that could be improved upon: The
collaborators can be given a weak_ptr only. But, we may require that collaborators have owning references. In my library, a "borrower" (weak_ptr) could optionally hold a strong reference as well, so the reference could be upgraded from weak to strong after a point of commitment is reached.
If there were some kind of on-spec pending ptr type, they could be seen as strong references eventually and in normal use, but automatically cleared or committed by the Create wrapper. That is, you would not have to keep track of the collaborators and hook them up in a second stage; rather, all such pending ptrs would become solid (wherever they are) with one call made after the ctor is golden. I never had a problem with it, though. —John
participants (1)
-
John M. Dlugosz