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


weak_ptr::use_count

Количество чисел shared_ptr обозначенных объектов.

long use_count() const;

Заметки

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

Пример

 

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

Требования

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

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

См. также

Ссылки

weak_ptr Class