Capture shared_ptr in lambda

I want to capture a shared_ptr in my lambda expression. Tried two methods: Capture the shared pointer error: invalid use of non-static data member A::ptr Create a weak pointer and capture it (Found this via some results online). I’m not sure if I’m doing it the right way error: ‘const class std::weak_ptr’ has no member… Read More Capture shared_ptr in lambda

Calling `.lock()` on weak_ptr returns NULL shared_ptr

I am somewhat confused by the behaviour of the .lock() call on a weak_ptr. My understanding is that .lock() will return a shared_ptr of the relevant type if it has not expired otherwise it will be a null pointer. From https://en.cppreference.com/w/cpp/memory/weak_ptr/lock : A shared_ptr which shares ownership of the owned object if std::weak_ptr::expired returns false.… Read More Calling `.lock()` on weak_ptr returns NULL shared_ptr