【问题标题】:Forward declration using Template template parameters使用模板模板参数的前向声明
【发布时间】:2014-12-14 21:18:51
【问题描述】:

对于我的一生,我无法编译这个前向声明。一切看起来语法正确,但我收到类型/值不匹配错误。

namespace C {
   template <class TBinaryPredicate> class E;
}

template< template<typename> class TField> class CF;

using CE_Less = C::E<std::less<Date>>;
using CF_Less = CF<CE_Less>;  <==== COMPILER NOT HAPPY HERE

编译器错误:

错误:“模板类 TField> 类 CF”的模板参数列表中参数 1 的类型/值不匹配

声明此模板别名的正确方法是什么?

【问题讨论】:

  • CF 需要模板作为参数,但CE_Less 不是模板;它是一个具体的类(通过实例化模板获得)。你能解释一下你想做什么吗?
  • 语法上看起来没有什么是正确的。是什么给了你这样的印象?

标签: c++ templates


【解决方案1】:

CF 需要一个模板:CE_Less 不是模板别名,它是一个简单的别名,您可能打算使用模板别名:

template<class T>
using CE_Less = C::E<std::less<T>>;

using CF_Less = CF< CE_Less >; 

【讨论】: