411 REFERENCE · Wikibooks
C++ Language/Indirection/SmartPointers/ReturningThis
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Traditional C++ code might sometimes have wanted to do return this; (returning a CRType* raw pointer).
To instead return std::shared_ptr<CRType>, derive your class from std::enable_shared_from_type<CRType> (so that an internal std::shared_ptr<> will start owning this object), and return shared_from_this() instead of this.
Additional information about returning the this pointer as a smart pointer (includes interactive examples)