- std::enable_shared_from_this is a base class template
- shared_from_this() is the member function provided
- CRTP is needed when you derive from this base class.
- underlying problem (target of this solution) — buggy design where two separate “clubs” centered around the same raw ptr. Each club thinks it owns the raw ptr and would destroy it independently.
- usage example —
- your host class is already managed via a shared_ptr
- your instance method need to create new shared_ptr objects from “this”
- Note if you only need to access “this” you won’t need the complexity here.
Pimco asked it in 2017!