C++语言基础(14)-typeid
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 |

浙公网安备 33010602011771号