std::shared_ptr::use_count
来自cppreference.com
< cpp | memory | shared ptr
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
long use_count() const; |
||
Returns the number of different shared_ptr
instances (this included) managing the current object. If there is no managed object, 0 is returned.
目录 |
[编辑] 参数
(无)
[编辑] 返回值
the number of shared_ptr
instances managing the current object or 0 if there is no managed object.
[编辑] 示例
#include <memory> #include <iostream> void fun(std::shared_ptr<int> sp) { std::cout << "fun: sp.use_count() == " << sp.use_count() << std::endl; } int main() { std::shared_ptr<int> sp1 {std::make_shared<int>(5)}; std::cout << "sp1.use_count() == " << sp1.use_count() << std::endl; fun(sp1); }
输出:
sp1.use_count() == 1 fun: sp.use_count() == 2
[编辑] 另请参阅
检查是否被管理对象的管理仅由当前 shared_ptr 的实例 原文: checks whether the managed object is managed only by the current shared_ptr instance (公共成员函数) |