模板函数作为模板函子的模板参数
Template function as template argument for template functor
我想做这样的事情,有人知道这是否可能吗?
template<typename T> using pLearn = T (*)(T, T, const HebbianConf<T> &);
template<typename T> using pNormal = T (*)(T, T);
template<typename T> using pDerivative = T (*)(T, T, T);
template <class Type, pLearn LearnCB, pNormal NormalCB, pDerivative DerivCB>
class TransfFunction {
public:
static Type learn(Type a, Type b, const HebbianConf<Type> &setup) { return LearnCB<Type>(a, b, setup); };
static Type normal(Type a, Type b) { return NormalCB<Type>(a, b); };
static Type normal(Type a, Type b, Type c) { return DerivCB<Type>(a, b, c); };
};
错误:
In file included from /Functions.cpp:2:0:
/Functions.h:207:23: error: ‘pLearn’ is not a type
template <class Type, pLearn LearnCB, pNormal NormalCB, pDerivative DerivCB>
^
/Functions.h:207:39: error: ‘pNormal’ is not a type
template <class Type, pLearn LearnCB, pNormal NormalCB, pDerivative DerivCB>
^
/Functions.h:207:57: error: ‘pDerivative’ is not a type
template <class Type, pLearn LearnCB, pNormal NormalCB, pDerivative DerivCB>
错误说明了一切:
In file included from /Functions.cpp:2:0:
/Functions.h:207:23: error: ‘pLearn’ is not a type
template <class Type, pLearn LearnCB, pNormal NormalCB, pDerivative DerivCB>
^
pLearn
不是类型-pLearn
是别名模板。模板非类型参数需要类型。您需要为它提供类型参数。其他两个相同:
template <class Type,
pLearn<Type> LearnCB,
pNormal<Type> NormalCB,
pDerivative<Type> DerivCB>
class TransfFunction { ... };
相关文章:
- 将可变参数函数的参数封装在类实例中
- QML 使用带有参数C++函数
- 使用可变参数函数作为模板参数
- 如何在C++中伪造虚拟可变参数函数模板?
- 为什么可变参数函数不适用于模板
- C++ std::functional 中的可变参数函数模板
- 可变参数函数指针的定义对于VxWorks spyLib来说不清楚
- 使用可变参数函数覆盖具有不同函数签名的虚函数
- 考虑引用和常量的可变参数函数包装器
- 使用可变参数函数将整数和/或整数数组放入单个 int 数组中
- 在可变参数函数中转发特定范围的参数
- 通过引用传递参数;函数返回类型是否必须为 VOID?
- 使用带有一个参数函数的递归找到数字的平方
- 可变参数函数模板不能很好地使用 std::function 作为参数
- 多个可变参数函数的单个模板参数包?
- 参数数据类型未知的可变参数函数
- 可变参数函数参数包扩展
- 使用模板可变参数函数将多个参数传递给另一个函数
- 对可变参数函数的递归调用的链接器错误
- 通过像printf这样的可变参数函数传递一个带有常量字符*转换函数的类