When is std::weak_ptr useful?
问题 I started studying smart pointers of C++11 and I don\'t see any useful use of std::weak_ptr . Can someone tell me when std::weak_ptr is useful/necessary? 回答1: A good example would be a cache. For recently accessed objects, you want to keep them in memory, so you hold a strong pointer to them. Periodically, you scan the cache and decide which objects have not been accessed recently. You don't need to keep those in memory, so you get rid of the strong pointer. But what if that object is in use