C++ Exception 库 - bad_weak_ptr
描述
这是一个不好的弱指针。
声明
以下是 std::bad_weak_ptr 的声明。
class bad_weak_ptr: public exception;
C++11
class bad_weak_ptr: public exception;
参数
none
返回值
none
异常
No-throw guarantee − 没有成员抛出异常。
示例
在下面的 std::bad_typeid 示例中。
#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';
}
}
示例输出应该是这样的 −
bad_weak_ptr

