首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

几行模板代码,算是"重载"还是算"特化"呢? 分不清了,该如何解决

2012-06-08 
几行模板代码,算是重载还是算特化呢? 分不清了VC2010支持的C++11的functional里面有下面的代码:C/C+

几行模板代码,算是"重载"还是算"特化"呢? 分不清了
VC2010支持的C++11的<functional>里面有下面的代码:

C/C++ code
template<int _Nx>    class _Ph    {    // placeholder    };template<class _Tx>    struct is_placeholder    {    // template to indicate that _Tx is not a placeholder    static const int value = 0;    };template<int _Nx>    struct is_placeholder<_Ph<_Nx> >    {    // template specialization to indicate that _Ph<_Nx> is a placeholder    static const int value = _Nx;    };


这里的两个is_placeholder,算是2个重载呢? 还是下面的<int _Nx>版本算是一个特化呢?
模板函数,怎么才算重载,怎么才算特化?
谢谢!

[解决办法]
主模板
template<class _Tx>
struct is_placeholder
{ // template to indicate that _Tx is not a placeholder
static const int value = 0;
};
特化
template<int _Nx> struct is_placeholder<_Ph<_Nx> > { // template specialization to indicate that _Ph<_Nx> is a placeholder static const int value = _Nx; };
[解决办法]
探讨

引用:
主模板
template<class _Tx>
struct is_placeholder
{ // template to indicate that _Tx is not a placeholder
static const int value = 0;
};
特化
template<int _Nx> struct is_placeholder<_P……

热点排行