std::bad_cast
Aus 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. |
definiert in Header <typeinfo> | ||
class bad_cast :publicstd::exception; | ||
Eine Ausnahme von dieser Art wird ausgelöst, wenn ein dynamic_cast zu einer Referenz-Typ die Laufzeit-Anreise (z. B. weil die Typen nicht durch Vererbung verbunden sind) nicht .
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.
Inhaltsverzeichnis |
[Bearbeiten]Member-Funktionen
baut eine neue bad_cast Objekt 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. (öffentliche Elementfunktion) |
Inherited from std::exception
Member functions
[virtuell] | Zerstört das Ausnahme-Objekt 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. (virtuellen öffentlichen Member-Funktion of std::exception ) |
[virtuell] | gibt einen erläuternden String 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. (virtuellen öffentlichen Member-Funktion of std::exception ) |
[Bearbeiten]Beispiel
#include <iostream>#include <typeinfo> struct Foo {virtualvoid f(){}};struct Bar {virtualvoid 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!