<1>在#define中使用typeofide
#define max(x,y)({typeof(x) _x=x;typeof(y) _y=y; _x>_y?_x:_y;})spa
<2>#include <typeinfo>it
模板類:模板
template<typename T> class PrintTypeName {class
public:im
PrintTypeName (const char* pszLable) {margin
const type_info&ti = typeid (T);top
cout << pszLable << ti.name () << endl;di
}view
};
使用:PrintTypeName<char> ("char:");
結果:char:char