2 Matching Annotations
  1. Apr 2022
    1. std::shared_ptr can be used when you need multiple smart pointers that can co-own a resource. The resource will be deallocated when the last std::shared_ptr goes out of scope. std::weak_ptr can be used when you want a smart pointer that can see and use a shared resource, but does not participate in the ownership of that resource.

      weak_ptr 的适用场景

    1. Always make a copy of an existing std::shared_ptr if you need more than one std::shared_ptr pointing to the same resource.

      如果要创建多个 shared_ptr,推荐的做法是什么?