Namespaces
Variants

std::bad_function_call

ja.cppreference.net より
 
 
ユーティリティライブラリ
言語サポート
型サポート (基本型、RTTI)
ライブラリ機能テストマクロ (C++20)
プログラムユーティリティ
可変長引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)(C++20)(C++20)    
(C++20)
swap と 型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
共通語彙型
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
関数オブジェクト
関数呼び出し
(C++17)(C++23)
恒等関数オブジェクト
(C++20)
透過的な演算子ラッパー
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

旧式のバインダとアダプタ
(C++17まで*)
(C++17まで*)
(C++17まで*)
(C++17まで*)  
(C++17まで*)
(C++17まで*)(C++17まで*)(C++17まで*)(C++17まで*)
(C++20まで*)
(C++20まで*)
(C++17まで*)(C++17まで*)
(C++17まで*)(C++17まで*)

(C++17まで*)
(C++17まで*)(C++17まで*)(C++17まで*)(C++17まで*)
(C++20まで*)
(C++20まで*)
 
ヘッダ <functional>
class bad_function_call;

std::bad_function_call で定義される例外の型であり、関数ラッパーにターゲットがない場合に std::function::operator() によって投げられる。

cpp/error/exception

継承図

メンバー関数

(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)
任意のコピー構築可能な呼び出し可能オブジェクトのコピー可能ラッパー
(クラステンプレート)