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 는 함수 래퍼가 대상(target)을 가지고 있지 않을 때 std::function::operator() 에 의해 던져지는 예외의 타입입니다.

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

상속 다이어그램

목차

멤버 함수

(생성자)
새로운 bad_function_call 객체를 생성함
(public 멤버 함수)
operator=
bad_function_call 객체를 대체함
(public 멤버 함수)
what
설명 문자열을 반환함
(public 멤버 함수)

std::bad_function_call:: bad_function_call

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

새로운 bad_function_call 객체를 생성합니다. 이 객체는 구현에서 정의된 null-terminated 바이트 문자열을 가지며, 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 의 내용을 할당합니다. * this other 모두 동적 타입이 std::bad_function_call 인 경우, 할당 후 std:: strcmp ( what ( ) , other. what ( ) ) == 0 입니다.

매개변수

other - 할당할 다른 예외 객체

반환 값

* this

std::bad_function_call:: what

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

설명 문자열을 반환합니다.

반환값

설명 정보를 담은 구현 정의 널 종료 문자열에 대한 포인터. 이 문자열은 std::wstring 으로 변환 및 표시하기에 적합합니다. 이 포인터는 최소한 해당 포인터를 얻은 예외 객체가 소멸되거나, 예외 객체의 비상수 멤버 함수(예: 복사 할당 연산자)가 호출되기 전까지는 유효함이 보장됩니다.

참고

구현체는 what() 을 재정의할 수 있지만 필수는 아닙니다.

std::exception에서 상속됨

멤버 함수

[virtual]
예외 객체를 파괴함
( std::exception 의 virtual public 멤버 함수)
[virtual]
설명 문자열을 반환함
( std::exception 의 virtual public 멤버 함수)

예제

#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)
복사 생성 가능한 모든 호출 가능 객체의 복사 가능 래퍼
(클래스 템플릿)