std::bad_typeid
提供: cppreference.com
<tbody>
</tbody>

| ヘッダ <typeinfo> で定義
|
||
class bad_typeid : public std::exception; |
||
多相型のヌルポインタ値の逆参照に typeid 演算子が適用されたとき、この型の例外が投げられます。
継承図
メンバ関数
新しい bad_typeid オブジェクトを構築します (パブリックメンバ関数) |
std::exception から継承
メンバ関数
[仮想] |
例外オブジェクトを破棄します ( std::exceptionの仮想パブリックメンバ関数)
|
[仮想] |
説明文字列を返します ( std::exceptionの仮想パブリックメンバ関数)
|
例
Run this code
#include <iostream>
#include <typeinfo>
struct S { // The type has to be polymorphic
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!