参考网址:
https://zh.cppreference.com/w/cpp/header
https://blog.csdn.net/w55100/article/details/80330812
工具库
typeinfo
运行时类型信息工具
类
namespace std {
//含有某个类型的信息,由实现生成。这是 typeid 运算符所返回的类。
class type_info;
//当 typeid 表达式中的实参为空值时抛出的异常
class bad_cast;
由非法的 dynamic_cast 表达式抛出的异常,即引用类型转型失败
class bad_typeid;
}
用途
typeid是C++的关键字之一,等同于sizeof这类的操作符,返回结果是名为type_info的标准库类型的对象的引用。类包含的参数和成员函数的功能:
-> 创建一个引用对象 const type_info& t0 = typeid(int);
-> 获得类型名称 const char* b=t0.name();
->比较对象是否相等,仅支持2种比较符
t1 == t2 ,t1 != t2
程序实例1:
#include <iostream>
#include <typeinfo>
struct Base {