您的位置:首页 > 运维架构 > Linux

Linux C/C++ 模板:针对类型信息的特化

2015-04-11 00:51 211 查看
一、代码

#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;
}
二、输出结果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐