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);
}
需求
標頭: <memory>
命名空間: std