c – 为什么默认模板参数的模板不能用作模板模板参数中具有较少模板参数的模板

myTemplateTemplate期望第二个模板参数是一个带有一个参数的模板.
myDefaultTemplate是一个带有两个参数的模板,第二个参数的认值为int.

在VS2008中,我得到编译错误:类模板’myDefaultTemplate’的模板参数列表与模板参数’TT’的模板参数列表不匹配

那么为什么myDefaultTemplate不能用作一个参数的模板呢?
如果C编译器支持它会有任何负面影响吗?

template
<typename T1,typename T2 = int>
class
myDefaultTemplate{
      T1 a;
      T2 b;
};

template
<typename T1,template<typename T2> class TT>
class
myTemplateTemplate{
      T1 a;
      TT<T1> b;
};

int main(int argc,char* argv[]){
      myTemplateTemplate<int,myDefaultTemplate> bar; //error here:      
      return 0;
}

解决方法

从标准(见14.3.3第1段 – [temp.arg.template]):

A template-argument for a template template-parameter shall be the
name of a class template,expressed as id-expression. Only primary
class templates are considered when matching the template template
argument with the corresponding parameter; partial specializations are
not considered even if their parameter lists match that of the
template template parameter.

这意味着模板myDefaultTemplate将只被视为2参数模板.认参数不会被考虑.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...