std::bad_cast
De 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. |
Déclaré dans l'en-tête <typeinfo>
|
||
class bad_cast : public std::exception; |
||
Une exception de ce type est levée lorsqu'une dynamic_cast à un type référence échoue au contrôle de l'exécution (par exemple, parce que les types ne sont pas liées par héritage) .
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.
Sommaire |
[modifier] Fonctions membres
construit un objet bad_cast nouvelle 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. (fonction membre publique) |
Inherited from std::exception
Member functions
[ virtuel ]Original: virtual The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Détruit l'objet exception 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. (function membre virtuelle publique de std::exception )
|
[ virtuel ]Original: virtual The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
retourne une chaîne explicative 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. (function membre virtuelle publique de std::exception )
|
[modifier] Exemple
#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'; } }
Résultat :
Bad dynamic_cast!