typeid可用来判断类型是否相等:

例如有下面的定义:

char *str;
int a = 2;
int b = 10;
float f;
类型比较 结果 类型比较 结果
typeid(int) == typeid(int) true typeid(int) == typeid(char) false
typeid(char*) == typeid(char) false typeid(str) == typeid(char*) true
typeid(a) == typeid(int) true typeid(b) == typeid(int) true
typeid(a) == typeid(a) true typeid(a) == typeid(b) true
typeid(a) == typeid(f) false typeid(a/b) == typeid(int) true

 

相关文章:

  • 2021-06-20
  • 2021-06-27
  • 2021-07-19
猜你喜欢
  • 2021-08-31
  • 2021-07-29
  • 2021-09-26
  • 2021-09-04
相关资源
相似解决方案