3 ms·
This question was genuine curiosity so I'm a bit disappointed there was never a reply. On reflection, I suspect the parent comment was referring to creating ci
by quietbritishjim 5y ago
This question was genuine curiosity so I'm a bit disappointed there was never a reply.
On reflection, I suspect the parent comment was referring to creating circular dependencies using lambdas and std::function.
For example, a class Inner wants allow notifying its owner when events happen, so it has a std::function member variable it uses for the callback function, and a class Outer has an instance of Inner as a member variable. But then passes as a callback:
m_inner.set_callback([self=this->shared_from_this()](Param p){ self->handle_inner(p); });
Now Outer owns Inner (directly) and Inner holds a shared_ptr to Outer, so Outer will never be destroyed (and therefore neither will Inner).