bad_weak_ptr Class

将报告坏 weak_ptr 异常。

class bad_weak_ptr
    : public std::exception {
public:
    bad_weak_ptr();
    const char *what() throw();
    };

备注

该类描述从引发的异常shared_ptr Class类型作为参数的构造函数weak_ptr Class。该成员函数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>

命名空间: 标准

请参见

参考

weak_ptr Class

其他资源

memory 成员