shared_ptr::reset
소유한 리소스를 대체합니다.
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
The deleter to copy.A
할당자 형식입니다.alloc
The allocator to copy.
설명
The operators all decrement the reference count for the resource currently owned by *this and assign ownership of the resource named by the operand sequence to *this. If the reference count falls to zero, the resource is released. If an operator fails it leaves *this unchanged.
예제
// 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);
}
요구 사항
헤더 <memory>
네임스페이스: std