本文整理汇总了C++中std::weak_ptr::use_count方法的典型用法代码示例。如果您正苦于以下问题:C++ weak_ptr::use_count方法的具体用法?C++ weak_ptr::use_count怎么用?C++ weak_ptr::use_count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::weak_ptr
的用法示例。
在下文中一共展示了weak_ptr::use_count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f
/* Notes *
* std::weak_ptr *
expired - checks whether the referenced object was already deleted
lock - creates a shared_ptr that manages the referenced object
* std::unique_ptr * ,using this instead of auto_ptr considering:
1 - operators supported(==, !=, < ...),so they can be used/stored in STL
which uses/relies on a lot of these operations
2 - array supported, can point to an array
*/
void f()
{
if ( !wp.expired()) {
auto spt = wp.lock();
std::cout << *spt << "\n";
std::cout << wp.use_count() << "\n";
}
else {
std::cout << "wp is expired\n";
}
}