名前空間
変種
操作

std::bad_typeid

提供: cppreference.com
< cpp‎ | types
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ(C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
型サポート
型の性質
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(C++20未満)
(C++11)(C++20で非推奨)
(C++11)
型特性定数
メタ関数
(C++17)
定数評価文脈
サポートされている操作
関係と性質の問い合わせ
型変更
型変換
(C++11)
(C++11)
(C++17)
(C++11)(C++20未満)(C++17)
 
 
ヘッダ <typeinfo> で定義
class bad_typeid :publicstd::exception;

多相型のヌルポインタ値の逆参照に typeid 演算子が適用されたとき、この型の例外が投げられます。

cpp/error/exceptionstd-bad typeid-inheritance.svg
画像の詳細

継承図

目次

[編集]メンバ関数

新しい bad_typeid オブジェクトを構築します
(パブリックメンバ関数)

std::exception から継承

メンバ関数

例外オブジェクトを破棄します
(std::exceptionの仮想パブリックメンバ関数)[edit]
[仮想]
説明文字列を返します
(std::exceptionの仮想パブリックメンバ関数)[edit]

[編集]

#include <iostream>#include <typeinfo>   struct S {// The type has to be polymorphicvirtualvoid 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!
close