天天看點

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