bad_weak_ptr
描述 (Description)
这是一个糟糕的弱指针。
声明 (Declaration)
以下是std :: bad_weak_ptr的声明。
class bad_weak_ptr: public exception;
C++11
class bad_weak_ptr: public exception;
参数 (Parameters)
没有
返回值 (Return Value)
没有
异常 (Exceptions)
No-throw guarantee - 没有成员抛出异常。
例子 (Example)
在下面的示例中为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