typeid 是运算符,检查 表达式的 类型:typeid (表达式)计算返回 type_info 型的 常对象地址,头文件 <typeinfo>里定义。.name() 返回类型名字。书上例子:#include <iostream>#include <typeinfo>usingnamespace std;int main () {int * a,b;a=0; b=0;if (typeid(a) != typeid(b)){cout << "a and b are of different types:\n";cout << "a is: " << typeid(a).name() << '\n';cout << "b is: " << typeid(b).name() << '\n';}return 0;}输出:a and b are of different types:a is: int *b is: int如果是 class , 它能返回 class 名字。