定义于头文件
<memory>
|
||
class bad_weak_ptr;
|
(C++11 起) | |
std::bad_weak_ptr
是 std::shared_ptr 以 std::weak_ptr 为参数的构造函数,在 std::weak_ptr 指代已被删除的对象时,作为异常抛出的对象类型。
目录 |
(构造函数)
|
构造 bad_weak_ptr 对象 (公开成员函数) |
bad_weak_ptr() noexcept;
|
||
构造 std::bad_weak_ptr
的新实例。 what()
返回实现定义的空终止字节字符串。
(无)
[虚]
|
析构该异常对象 ( std::exception 的虚公开成员函数)
|
[虚]
|
返回解释性字符串 ( std::exception 的虚公开成员函数)
|
#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)
|
拥有共享对象所有权语义的智能指针 (类模板) |
(C++11)
|
由std::shared_ptr所管理的对象的弱引用 (类模板) |