std::bad_typeid
From cppreference.com
| ヘッダ <typeinfo> で定義 |
||
| class bad_typeid : public std::exception; |
||
多態型へのヌルポインタ値に対する typeid 演算子の適用時に、この型の例外がスローされます。
継承図
目次 |
[編集] メンバ関数
| (コンストラクタ) |
新しい bad_typeid オブジェクトを構築します(public member function) |
| operator= |
bad_typeid オブジェクトを置き換えます(public member function) |
| what |
説明文字列を返す (public member function) |
std::bad_typeid::bad_typeid
| (1) | ||
bad_typeid() throw(); |
(C++11まで) | |
| bad_typeid() noexcept; |
(C++11以降) | |
| (2) | ||
bad_typeid( const bad_typeid& other ) throw(); |
(C++11まで) | |
| bad_typeid( const bad_typeid& other ) noexcept; |
(C++11以降) | |
what() 経由でアクセス可能な、実装定義のヌル終端バイト文字列で新しい bad_typeid オブジェクトを構築します。
1) デフォルトコンストラクタ。
2) コピーコンストラクタ。 もし *this と other が両方とも動的型
std::bad_typeid を持つ場合、代入後の std::strcmp(what(), other.what()) == 0 となります。(C++11 以降)パラメータ
| その他 | - | コピーする別の例外オブジェクト |
std::bad_typeid::operator=
| bad_typeid& operator=( const bad_typeid& other ) throw(); |
(C++11まで) | |
| bad_typeid& operator=( const bad_typeid& other ) noexcept; |
(C++11以降) | |
other の内容を代入します。もし *this と other が両方とも動的型 std::bad_typeid を持つ場合、代入後の std::strcmp(what(), other.what()) == 0 となります。(C++11 以降)
パラメータ
| その他 | - | 割り当てる別の例外オブジェクト |
戻り値
*this
std::bad_typeid::what
| virtual const char* what() const throw(); |
(C++11まで) | |
virtual const char* what() const noexcept; |
(C++11以降) (C++26 以降 constexpr) |
|
説明文字列を返します。
戻り値
説明情報を含む、実装定義のヌル終端文字列へのポインタ。この文字列は std::wstring として変換および表示するのに適しています。このポインタは、それが取得された例外オブジェクトが破棄されるか、例外オブジェクトの非 const メンバー関数(例:コピー代入演算子)が呼び出されるまで、少なくとも有効であることが保証されます。
|
返された文字列は、定数評価中に通常のリテラルエンコーディングでエンコードされます。 |
(C++26以降) |
注釈
実装は what() をオーバーライドすることが許可されていますが、必須ではありません。
std::exception から継承
メンバ関数
| [virtual] |
例外オブジェクトを破棄する ( std::exception の仮想 public メンバー関数) |
| [virtual] |
説明文字列を返す ( std::exception の仮想 public メンバー関数) |
[編集] 注記
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_constexpr_exceptions |
202411L |
(C++26) | constexpr for exception types |
[編集] 例
このコードを実行
実行結果の例
Attempted a typeid of NULL pointer!