替换拥有的资源。
void reset();
template<class Other>
void reset(Other *ptr;);
template<class Other, class D>
void reset(Other *ptr, D dtor);
template<class Other, class D, class A>
void reset(Other *ptr, D dtor, A alloc);
参数
Other
由参数指针控制的类型。D
删除器的类型。ptr
复制的指针。dtor
复制的 deleter。A
分配算符的类型。alloc
复制的分配器。
备注
运算符资源的引用计数由 *this 当前拥有的所有减量,并且资源分配的所有权。操作数序列到名为 *this。 如果引用数为零,此资源的释放。 运算符如果失败它保持不更改 *this。
示例
// std_tr1__memory__shared_ptr_reset.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
struct deleter
{
void operator()(int *p)
{
delete p;
}
};
int main()
{
std::shared_ptr<int> sp(new int(5));
std::cout << "*sp == " << std::boolalpha
<< *sp << std::endl;
sp.reset();
std::cout << "(bool)sp == " << std::boolalpha
<< (bool)sp << std::endl;
sp.reset(new int(10));
std::cout << "*sp == " << std::boolalpha
<< *sp << std::endl;
sp.reset(new int(15), deleter());
std::cout << "*sp == " << std::boolalpha
<< *sp << std::endl;
return (0);
}
要求
页眉: <内存>
命名空间: std