Поделиться через


shared_ptr::~shared_ptr

Удаляет shared_ptr.

~shared_ptr();

Заметки

Деструктор уменьшает счетчик ссылок ресурса в данный момент принадлежит *this.Если значение счетчика ссылок передается нулевое значение, то ресурс освобождается.

Пример

 

// std_tr1__memory__shared_ptr_destroy.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
struct deleter 
    { 
    void operator()(int *p) 
        { 
        delete p; 
        } 
    }; 
 
int main() 
    { 
    std::shared_ptr<int> sp1(new int(5)); 
    std::cout << "*sp1 == " << *sp1 << std::endl; 
    std::cout << "use count == " << sp1.use_count() << std::endl; 
 
     { 
    std::shared_ptr<int> sp2(sp1); 
    std::cout << "*sp2 == " << *sp2 << std::endl; 
    std::cout << "use count == " << sp1.use_count() << std::endl; 
     } 
 
// check use count after sp2 is destroyed 
    std::cout << "use count == " << sp1.use_count() << std::endl; 
 
    return (0); 
    } 
 
  

Требования

заголовок: <memory>

std пространство имен:

См. также

Ссылки

shared_ptr Class