[英]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.