记录http://en.cppreference.com/w/cpp/memory/unique_ptr/reset,
void reset( pointer ptr = pointer() );
template< class U >
void reset( U ) = delete;
void reset( std::nullptr_t p );
Run Code Online (Sandbox Code Playgroud)
1)给定
current_ptr,由其管理的指针按*this以下顺序执行以下操作:保存当前指针的副本old_ptr = current_ptr; 用参数覆盖当前指针current_ptr = ptr; 如果旧指针非空,则删除以前管理的对象if(old_ptr != nullptr) get_deleter()(old_ptr).2)在动态数组的特化中,
std::unique_ptr<T[]>提供此模板成员是为了防止使用reset()指向派生的指针(这将导致数组的未定义行为).3)在动态数组的专门化中
std::unique_ptr<T[]>,第三个重载是必要的,以允许重置nullptr(否则模板重载将禁止).相当于reset(pointer())
现在这reset(nullptr)相当于reset(pointer()),为什么后者存在?
如果我想重置一个数组形式unique_ptr,为什么我不能只使用rest(pointer())?