◐ Shell
clean mode source ↗

std::bad_typeid - cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

Definido no cabeçalho

<typeinfo>

class bad_typeid : public std::exception;

Uma excepção deste tipo é lançada quando um operador

typeid

é aplicada para um valor nulo dereferenced ponteiro ou um tipo polimórfico.

Original:

An exception of this type is thrown when a

typeid

operator is applied to a dereferenced null pointer value or a polymorphic type.

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

Funções de membro

constrói um objeto bad_typeid novo

Original:

constructs a new bad_typeid object

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(função pública membro)

Herdado de std::exception

Member functions

destrói o objeto de exceção

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 função pública virtual membro) [edit]

retorna uma cadeia explicativa

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 função pública virtual membro) [edit]

Exemplo

#include <iostream>
#include <typeinfo>

struct S { // The type has to be polymorphic
    virtual void f();
}; 

int main()
{
    S* p = nullptr;
    try {
        std::cout << typeid(*p).name() << '\n';
    } catch(const std::bad_typeid& e) {
        std::cout << e.what() << '\n';
    }
}

Saída:

Attempted a typeid of NULL pointer!