std::bad_weak_ptr
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| 在头文件 <memory> 中定义
|
||
| class bad_weak_ptr; |
(C++11 起) | |
std::bad_weak_ptr是std::shared_ptr,std::weak_ptr的说法,当std::weak_ptr指的是一个已被删除的对象的构造函数抛出的异常对象的类型.原文:
std::bad_weak_ptr is the type of the object thrown as exceptions by the constructors of std::shared_ptr that take std::weak_ptr as the argument, when the std::weak_ptr refers to an already deleted object.目录 |
[编辑] 成员函数
| 构建 bad_weak_ptr对象(公共成员函数) | |
Inherited from std::exception
Member functions
| [虚]</div></div>
|
析构该异常对象 ( std::exception的公有虚成员函数)
|
| [虚]</div></div>
|
返回一个说明字符串 ( std::exception的公有虚成员函数)
|
</div>
[编辑] 示例
#include <memory> #include <iostream> int main() { std::shared_ptr<int> p1(new int(42)); std::weak_ptr<int> wp(p1); p1.reset(); try { std::shared_ptr<int> p2(wp); } catch(const std::bad_weak_ptr& e) { std::cout << e.what() << '\n'; } }
输出:
std::bad_weak_ptr
[编辑] 另请参阅
| (C++11) |
smart pointer with shared object ownership semantics (类模板) |
| (C++11) |
std::shared_ptr管理对象的弱引用 原文: weak reference to an object managed by std::shared_ptr (类模板) |
