目录

bad_typeid

描述 (Description)

在null指针的typeid上抛出此异常。

声明 (Declaration)

以下是std :: bad_typeid的声明。

class bad_typeid;

C++11

class bad_typeid;

参数 (Parameters)

没有

返回值 (Return Value)

没有

异常 (Exceptions)

No-throw guarantee - 没有成员抛出异常。

例子 (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';
   }
}

样本输出应该是这样的 -

std::bad_typeid
↑回到顶部↑
WIKI教程 @2018