一、代码
#include <iostream>
using namespace std;
//针对类型信息的特化
//
template <typename T>
class IsInt
{
public:
enum { result = false };
};
//
template <>
class IsInt<int>
{
public:
enum { result = true };
};
int main(int argc, char*argv[])
{
IsInt<int>::result == true ? cout<<"int is int"<<endl : cout<<"int is not int"<<endl;
IsInt<char*>::result == true ? cout<<"char* is int"<<endl : cout<<"char* is not int"<<endl;
IsInt<float>::result == true ? cout<<"float is int"<<endl : cout<<"float is not int"<<endl;
return 0;
}
二、输出结果