<typeinfo>

std::bad_typeid

class bad_typeid;
對指向具有空指標值的多型型別的指標使用 typeid 時丟擲的異常

對指向具有空指標值的多型型別的指標使用 typeid 時丟擲的異常的型別。

其成員 what 返回一個標識異常的空終止字元序列

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// bad_typeid example
#include <iostream>       // std::cout
#include <typeinfo>       // operator typeid, std::bad_typeid

class Polymorphic {virtual void Member(){}};

int main () {
  try
  {
    Polymorphic * pb = 0;
	std::cout << typeid(*pb).name();
  }
  catch (std::bad_typeid& bt)
  {
    std::cerr << "bad_typeid caught: " << bt.what() << '\n';
  }
  return 0;
}

可能的輸出

bad_typeid caught: St10bad_typeid


異常安全

無異常保證:無成員丟擲異常。

另見