天天看点

typeid、typename、type_info

1. typename: 可以代替一切类型,如class,struct,long,int...

template <typename T>
class CFixT
{
  CFixT();
  ~CFixT();
};      

2. type_info: 类型信息;

3. typeid: 等同于sizeof这类的操作符,它是用于获取类型,typeid操作符返回的结果是type_info对象的引用;

const type_info &t0 = typeid(int);
const type_info &t1 = typeid(double);
const type_info &t2 = typeid(class Subject); //需要申明、定义一个类Subject

TRACE("T0: %s", t0.name());
TRACE("T1: %s", t1.name());
TRACE("T2: %s", t2.name());      
atlTraceGeneral - T0: int
atlTraceGeneral - T1: double
atlTraceGeneral - T2: class Subject