2016-05-17 9 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、...>'そして 'return 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は別名テンプレートです。テンプレート非型パラメータはタイプが必要です。型引数を指定する必要があります。他の2つに同じ:

template <class Type, 
      pLearn<Type> LearnCB, 
      pNormal<Type> NormalCB, 
      pDerivative<Type> DerivCB> 
class TransfFunction { ... }; 
関連する問題