◐ Shell
clean mode source ↗

std::bad_cast – cppreference.com

Aus cppreference.com

<metanoindex/>

<tbody> </tbody>

definiert in Header

<typeinfo>

class bad_cast : public std::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.

cpp/error/exception

Inheritance diagram

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

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) [edit]

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) [edit]

Beispiel

#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: