2 Matching Annotations
  1. Apr 2022
    1. Because std::unique_ptr is designed with move semantics in mind, copy initialization and copy assignment are disabled. If you want to transfer the contents managed by std::unique_ptr, you must use move semantics.

      std::unique_ptr 可以使用 copy 初始化吗?

    1. By default, C++ will provide a copy constructor and copy assignment operator if one is not explicitly provided. These compiler-provided functions do shallow copies, which may cause problems for classes that allocate dynamic memory. So classes that deal with dynamic memory should override these functions to do deep copies.

      c++ 默认提供什么样的 copy constructor,这会导致什么问题?