2016-05-17 203 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 { ... };