◐ Shell
clean mode source ↗

std::bad_cast - cppreference.com

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<metanoindex/>

<tbody> </tbody>

Elemento definito nell'header

<typeinfo>

class bad_cast : public std::exception;

Un'eccezione di questo tipo viene generata quando un

dynamic_cast

un tipo di riferimento non supera il run-time di controllo (ad esempio, perché i tipi non sono legati per via ereditaria).

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

Membri funzioni

costruisce un nuovo oggetto 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.


(metodo pubblico)

Inherited from std::exception

Member functions

distrugge l'oggetto eccezione

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.


(metodo pubblico virtuale) [modifica]

restituisce una stringa esplicativa

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.


(metodo pubblico virtuale) [modifica]

Esempio

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