bad_weak_ptr 类
报告错误 weak_ptr 异常。
class bad_weak_ptr
: public std::exception {
public:
bad_weak_ptr();
const char *what() throw();
};
备注
类描述可以从 shared_ptr 类 构造函数引发采用类型的参数异常。weak_ptr 类 成员函数 what 返回 "bad_weak_ptr"。
示例
// std_tr1__memory__bad_weak_ptr.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
int main()
{
std::weak_ptr<int> wp;
{
std::shared_ptr<int> sp(new int);
wp = sp;
}
try
{
std::shared_ptr<int> sp1(wp); // weak_ptr has expired
}
catch (const std::bad_weak_ptr&)
{
std::cout << "bad weak pointer" << std::endl;
}
catch (...)
{
std::cout << "unknown exception" << std::endl;
}
return (0);
}
要求
页眉: <内存>
命名空间: std