Quote:Original post by NitageThat sounds like a pretty bizarre use case. As you said, any situations where the user code has a raw pointer to the object yet knows that a shared_ptr exists, the user code could just as easily be given a shared_ptr to begin with. It's also clearly not the intended purpose of shared_from_this -- see the documentation for details, not to mention the very name of the utility. Apparently, the Boost developers felt that it was natural for a class to rely on its own ownership semantics.
To a certain extend, yes - but the coupling is less strong than if called in the constructors. There's nothing to stop a class from using enable_shared_from_this just so others can use shared_from_this on the precondition that is is being held by a shared_ptr elsewhere.
I think this might be a core point of contention between you and Burnhard. He cares about ownership flexibility at the class granularity; you care about it at the instance granularity too. I think for the majority of the nice, meaty classes one tends to hide behind shared_ptr-returning factory functions -- as opposed to Vec3 or ParsedURL -- I'm with him on that. It's natural for how a class' lifetime behaves to be considered part of its interface, and of course a class can rely on its own interface. And particularly in the realm of IOC, signal/slots, and other modern programming patterns, keeping the class from relying on it sharply limits your flexibility.