2016-05-17 233 views
1

我想要做这样的事情,有没有人有一个想法,是否有可能?作为模板函数的模板参数的模板函数

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> 
+1

您使用哪种编译器?适用于MSVS15 – Rakete1111

+2

为什么在以后使用此类型?为什么不'template LearnCB,...>'然后只是'返回LearnCB(a,b,setup);'? –

+0

认为这是不可能的,但工程。猜猜,这是解决方案 – dgrat

回答

4

错误说明了一切:

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 { ... };