◐ Shell
clean mode source ↗

std::bad_weak_ptr - cppreference.com

提供: cppreference.com

<tbody> </tbody>

class bad_weak_ptr;

(C++11以上)

std::bad_weak_ptr は、 std::weak_ptr がすでに削除されたオブジェクトを参照しているとき、引数として std::weak_ptr を取る std::shared_ptr のコンストラクタによって、例外として投げられるオブジェクトの型です。

cpp/error/exception

継承図

メンバ関数

bad_weak_ptr オブジェクトを構築します
(パブリックメンバ関数)

std::bad_weak_ptr ::bad_weak_ptr()

<tbody> </tbody>

std::bad_weak_ptr の新しいインスタンスを構築します。 what() は処理系定義のヌル終端バイト文字列を返します。

引数

(なし)

#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';
    }
}

出力:

関連項目