bad_weak_ptr 클래스

불량 weak_ptr 예외를 보고합니다.

구문

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

설명

이 클래스는 weak_ptr 클래스 형식의 인수를 사용하는 shared_ptr 클래스 생성자에서 throw될 수 있는 예외를 설명합니다. 멤버 함수 what에서 "bad_weak_ptr"을 반환합니다.

예시

// std__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);
}
bad weak pointer

참고 항목

weak_ptr 클래스