There seem to be two ways to temporarily grab ownership of the resource pointed to by a weak_ptr:
- Use lock()
- Pass the weak_ptr to a shared_ptr constructor
Both of these produce a shared_ptr, with the lock returning a nullptr in the case that the weak_ptr is empty and the shared_ptr constructor throwing an exception.
So the question is: when should one or the other be used? Are there general guidelines or best practices related to this?
Aucun commentaire:
Enregistrer un commentaire