Cpp-standard-library-cpp-bad-typeid
提供:Dev Guides
C ++ Type_infoライブラリ-bad_typeid
説明
nullポイントのtypeidで例外をスローします。
宣言
- 以下は、std
- bad_typeidの宣言です。
C 98
class bad_typeid;
C 11
class bad_typeid;
パラメーター
none
戻り値
none
例外
スロー不可の保証-このメンバー関数は例外をスローしません。
データの競合
ロケールオブジェクトが変更されます。
例
- 以下のstd
- bad_typeidの例。
#include <iostream>
#include <typeinfo>
struct S {
virtual void f();
};
int main() {
S* p = nullptr;
try {
std::cout << typeid(*p).name() << '\n';
} catch(const std::bad_typeid& e) {
std::cout << e.what() << '\n';
}
}
出力は次のようになります-
Attempted a typeid of NULL pointer!