2017-02-22 6 views
3

を推定することができないテンプレートパラメータが含まれていますエラー:クラステンプレート部分的な特殊化は、私は次のように減少してきた私のコードに来ていますこの問題で起こって何を考え出す助けに感謝したい

typedef unsigned short ushort; 

template<typename T = ushort*> 
struct Foo 
{ 
}; 

// Specialization -- works when not a specialization 
template< 
    template<typename,typename> class Container , 
    template<typename , template<typename,typename> class> class MetaFunction 
    > 
struct Foo<Container<ushort,typename MetaFunction<ushort,Container>::Type> > 
{ 
    //typedef Container<ushort,typename MetaFunction<ushort,Container>::Type> TestType; // OK 
}; 

int main() 
{ 
} 
コンパイルで

(GCC 5.4.0)私はエラーを取得する:

Test.cpp:14:8: error: template parameters not deducible in partial specialization: 
struct Foo<Container<ushort,typename MetaFunction<ushort,Container>::Type> > 
     ^
Test.cpp:14:8: note:   ‘template<class, template<class, class> class<template-parameter-2-2> > class MetaFunction’ 

は奇妙なことに、専門の引数Container<ushort,typename MetaFunction<ushort,Container>::Type>は有効であると表示されます。ここ

答えて

4

問題が

MetaFunction<ushort,Container>::Type 

があるということである非演繹ので、あなたの専門分野が有効でない場合、コンパイラはそれからテンプレート引数を推測することはできませんつまり、コンテキスト。 SO基本的には非推測コンテキストがIdentity<T>::typeのようなパターンで今

template<typename T> 
struct Identity 
{ 
    using type = T; 
}; 

に沸く

What is a nondeduced context?

を問う以前から、それについての詳細を読み、その理由を確認するには、Tはなりません私はそれがなぜそうであるのかを説明したリンクの例を再度参照してください。部分的な専門化と、タイプと専門家のメンバーとの間の1-1対応の欠如と関係しています。

関連する問題