Namespaces
Variants

std:: bad_function_call

From cppreference.net
Utilities library
Function objects
Function wrappers
(C++11)
(C++11)
bad_function_call
(C++11)
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
ヘッダーで定義 <functional>
class bad_function_call ;

std::bad_function_call は、関数ラッパーがターゲットを持たない場合に std::function::operator() によってスローされる例外の型です。

cpp/error/exception std-bad function call-inheritance.svg

継承図

目次

メンバー関数

(constructor)
新しい bad_function_call オブジェクトを構築する
(public member function)
operator=
bad_function_call オブジェクトを置き換える
(public member function)
what
説明文字列を返す
(public member function)

std::bad_function_call:: bad_function_call

bad_function_call ( ) noexcept ;
(1) (C++11以降)
bad_function_call ( const bad_function_call & other ) noexcept ;
(2) (C++11以降)

bad_function_call オブジェクトを構築します。実装定義のnull終端バイト文字列が含まれ、これは what() を通じてアクセス可能です。

1) デフォルトコンストラクタ。
2) コピーコンストラクタ。 * this other の両方が動的型 std::bad_function_call を持つ場合、 std:: strcmp ( what ( ) , other. what ( ) ) == 0 となります。

パラメータ

other - コピーする別の例外オブジェクト

std::bad_function_call:: operator=

bad_function_call & operator = ( const bad_function_call & other ) noexcept ;
(C++11以降)

内容を other の内容で代入します。 other * this の両方が動的型 std::bad_function_call を持つ場合、代入後は std:: strcmp ( what ( ) , other. what ( ) ) == 0 となります。

パラメータ

other - 代入する別の例外オブジェクト

戻り値

* this

std::bad_function_call:: what

virtual const char * what ( ) const noexcept ;
(C++11以降)

説明文字列を返します。

戻り値

説明情報を含む実装定義のナル終端文字列へのポインタ。この文字列は std::wstring への変換と表示に適しています。ポインタは、少なくとも取得元の例外オブジェクトが破棄されるまで、または例外オブジェクトの非constメンバー関数(コピー代入演算子など)が呼び出されるまで有効であることが保証されています。

注記

実装は what() をオーバーライドすることが許可されていますが、必須ではありません。

std::exception から継承 std:: exception

メンバー関数

[virtual]
例外オブジェクトを破棄
( std::exception の仮想公開メンバー関数)
[virtual]
説明文字列を返す
( std::exception の仮想公開メンバー関数)

#include <functional>
#include <iostream>
int main()
{
    std::function<int()> f = nullptr;
    try
    {
        f();
    }
    catch (const std::bad_function_call& e)
    {
        std::cout << e.what() << '\n';
    }
}

出力例:

bad function call

欠陥報告

以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。

DR 適用対象 公開時の動作 正しい動作
LWG 2233 C++11 what() は常に同じ説明文字列を返していた
std::exception::what()
独自の説明文字列を
返す

関連項目

(C++11)
任意のコピー構築可能な呼び出し可能オブジェクトのコピー可能ラッパー
(クラステンプレート)