There seem to be two ways to temporarily seize ownership of the resource pointed to by weak_ptr :
- Use
lock() - Pass
weak_ptr the shared_ptr constructor
Both of them produce shared_ptr , and the lock returns nullptr if weak_ptr empty and the shared_ptr constructor throws an exception.
So the question is: when should one or the other be used? Are there general recommendations or recommendations related to this?
source share