繁体   English   中英

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

[英]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是别名模板。 模板非类型参数需要type 您需要为其提供类型参数。 其他两个相同:

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