目录

bad_typeid

描述 (Description)

它会在null point的typeid上抛出异常。

声明 (Declaration)

以下是std :: bad_typeid的声明。

C++98

	
class bad_typeid;

C++11

class bad_typeid;

参数 (Parameters)

没有

返回值 (Return Value)

没有

异常 (Exceptions)

No-throw guarantee - 此成员函数永远不会抛出异常。

数据竞争 (Data races)

区域设置对象已修改。

例子 (Example)

在下面的示例中为std :: bad_typeid。

#include <iostream>
#include <typeinfo>
struct S {
   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!
↑回到顶部↑
WIKI教程 @2018