◐ Shell
clean mode source ↗

std::bad_typeid - cppreference.com

<tbody> </tbody>

class bad_typeid : public std::exception;

多相型のヌルポインタ値の逆参照に typeid 演算子が適用されたとき、この型の例外が投げられます。

cpp/error/exception

継承図

メンバ関数

新しい bad_typeid オブジェクトを構築します
(パブリックメンバ関数)

#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';
    }
}

出力:

Attempted a typeid of NULL pointer!