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


shared_ptr::use_count

Подсчитывает количество владельцев ресурса.

long use_count() const;

Заметки

Функция-член возвращает номер shared_ptr возражает, что имеют ресурс, который принадлежит *this.

Пример

 

// std_tr1__memory__shared_ptr_use_count.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
int main() 
    { 
    std::shared_ptr<int> sp1(new int(5)); 
    std::cout << "sp1.use_count() == " 
        << sp1.use_count() << std::endl; 
 
    std::shared_ptr<int> sp2(sp1); 
    std::cout << "sp1.use_count() == " 
        << sp1.use_count() << std::endl; 
 
    return (0); 
    } 
 
  

Требования

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

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

См. также

Ссылки

shared_ptr Class