shared_ptr::reset
Nahraďte zdroj vlastnictví.
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);
Parametry
Other
Typ řízena argument ukazatele.D
Typ deleter.ptr
Ukazatel ke kopírování.dtor
Deleter kopírovat.A
Typ modulu pro přidělování.alloc
Alokátor se kopírovat.
Poznámky
Všechny operátory snížit počet odkazů na daný zdroj aktuálně vlastněny *this a přiřazení vlastnictví zdroj s názvem sekvencí operand na *this.Pokud počet odkazů klesne na nulu, zdroj uvolněna.Pokud operátor selhání listy *this beze změny.
Příklad
// 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);
}
Požadavky
Záhlaví: <memory>
Obor názvů: std