std::bad_cast
提供:cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <typeinfo>
|
||
| class bad_cast : public std::exception; |
||
参照型へのdynamic_castは、ランタイムチェックを(型は継承によって関連していないなどの理由)が失敗した場合に、この型の例外がスローされます.
Original:
An exception of this type is thrown when a dynamic_cast to a reference type fails the run-time check (e.g. because the types are not related by inheritance).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目次 |
[編集] メンバ関数
| 新しいbad_castオブジェクトを作成します Original: constructs a new bad_cast object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (パブリックメンバ関数) | |
Inherited from std::exception
Member functions
| [仮想] |
例外オブジェクトを破棄します Original: destructs the exception object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (仮想パブリックメンバ関数of std::exception)
|
| [仮想] |
説明文字列を返します Original: returns an explanatory string The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (仮想パブリックメンバ関数of std::exception)
|
[編集] 例
#include <iostream> #include <typeinfo> struct Foo { virtual void f() {} }; struct Bar { virtual void f() {} }; int main() { Bar b; try { Foo& f = dynamic_cast<Foo&>(b); } catch(const std::bad_cast& e) { std::cout << e.what() << '\n'; } }
Output:
Bad dynamic_cast!
