简体   繁体   English

模板函数作为模板函子的模板参数

[英]Template function as template argument for template functor

I want to do something like this, does anyone has an idea whether it is possible? 我想做这样的事情,是否有人知道这是否可能?

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); };
};

Errors: 错误:

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>

The error says it all: 错误说明了一切:

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 is not a type - pLearn is an alias template. pLearn不是类型pLearn是别名模板。 Template non-type parameters need types . 模板非类型参数需要type You need to provide it with its type argument. 您需要为其提供类型参数。 Same for the other two: 其他两个相同:

template <class Type,
          pLearn<Type> LearnCB,
          pNormal<Type> NormalCB,
          pDerivative<Type> DerivCB>
class TransfFunction { ... };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM