详解C++编程中的sizeof运算符与typeid运算符

2020-01-06 14:23:36于海丽


// expre_typeid_Operator_2.cpp
#include <typeinfo>

int main()
{
  typeid(int) == typeid(int&); // evaluates to true
}
typeid 还可在模板中使用以确定模板参数的类型:
// expre_typeid_Operator_3.cpp
// compile with: /c
#include <typeinfo>
template < typename T > 
T max( T arg1, T arg2 ) {
  cout << typeid( T ).name() << "s compared." << endl;
  return ( arg1 > arg2 ? arg1 : arg2 );
}
 

注:相关教程知识阅读请移步到C++教程频道。