It\'s common to inherit from enable_shared_from_this
just to be able to return shared_ptr
\'s from member functions as the primary intention, with n
Since
private enable_shared_from_this
+ friendshared_ptr
seems to cover this use case, shouldn't it be sufficient by the standard?
No. The standard permits implementations wide latitude with how they implement things. The constructor of shared_ptr<T>
that adopts an object may defer the shared-from-this stuff to some helper function or other object. For maximum irony, it could defer to a base class of shared_ptr<T>
;)
As such, enable_shared_from_this
must be accessible by any code in order for the shared_ptr
constructor to work.