rptr = _ptr;
obj->unref_nodelete();
return rptr.valid();
}
这次你明白如果你意识到会有这种隐患的时候该怎么做了?我就不翻译了,看两个官方注释:
该函数的注释是:
/**
* Assign the observer_ptr to a ref_ptr. The ref_ptr will be valid if the
* referenced object hasn‘t been deleted and has a ref count > 0.
*/
还有对observer_ptr的注释:
* If you are in any doubt about whether it is safe to access the object safe then use the
* ref_ptr<> observer_ptr<>.lock() combination. */
全部完毕!