Is there a smart pointer that is automatically nulled when its target is destroyed in C++
问题 I've found QPointer. Are there any others? 回答1: Boost - the weak_ptr has some nice features that make it safe to use, if you are also using shared_ptr . You keep a weak_ptr reference to an instance that is managed by shared_ptr lifetime. When you need to use the underlying instance, convert it to a shared_ptr instance using the constructor of the shared_ptr class, or the lock method. The operation will fail if the underlying instance was deleted. The use is thread safe in the same fashion as