2017-02-08 42 views
3

どういうわけかDのインスタンスを作成できません。どうしてか分かりません。テンプレートテンプレートパラメータ(Allocator_class)が問題のようです。クランからコンストラクタを呼び出せません(テンプレートテンプレートパラメータ)

#include <vector> 

template <template<typename T> class Allocator_class> 
class T_b { 
public: 
    template<typename T> using A = Allocator_class<T>; 
}; 

template< template <typename T> class A> 
class C { 
public: 
    C() { } 
}; 

template<typename Ttb> 
class D { 
public: 
    template<typename T> using A = typename Ttb::template A<T>; 
    typedef C<A> Data; 

    D(C<A> &data) : _data(data) {} 
private: 
    Data &_data; 
}; 

int main() { 
    typedef T_b<std::allocator> Ttb;  
    C<std::allocator> b; 
    D<Ttb>c(b); 
} 

エラー:

test5.cpp:29:8: error: no matching constructor for initialization of 'D<Ttb>' 
     (aka 'D<T_b<std::allocator> >') 
     D<Ttb>c(b); 
      ^~ 
test5.cpp:16:7: note: candidate constructor (the implicit copy constructor) not viable: no known 
     conversion from 'C<std::allocator>' to 'const D<T_b<std::allocator> >' for 1st argument 
class D { 
    ^
test5.cpp:16:7: note: candidate constructor (the implicit move constructor) not viable: no known 
     conversion from 'C<std::allocator>' to 'D<T_b<std::allocator> >' for 1st argument 
class D { 
    ^
test5.cpp:21:5: note: candidate constructor not viable: no known conversion from 'C<std::allocator>' 
     to 'C<A> &' for 1st argument 
    D(C<A> &data) : _data(data) {} 
    ^
+0

は、この問題が発生したという理由があるのでしょうか? –

+0

おそらく[推論されないコンテキスト](http://stackoverflow.com/questions/25245453/what-is-a-nondeduced-context)? –

答えて

1

あなたのコードはエラーになりますなぜ私が説明することはできません。

しかし、あなたが解決したい場合は...クラス専門とテンプレートテンプレートテンプレートパラメータを使用して....

#include <vector> 

template <template<typename T> class Allocator_class> 
class T_b 
{ 
    public: 
     template<typename T> using A = Allocator_class<T>; 
}; 

template <template <typename T> class A> 
class C 
{ 
    public: 
     C() { } 
}; 

template <typename> 
class D; 

template <template <template <typename> class> class X, 
      template <typename> class A> 
class D<X<A>> 
{ 
    public: 
     using Data = C<A>; 

     D (Data & data) : _data(data) {} 

    private: 
     Data & _data; 
}; 

int main() 
{ 
    typedef T_b<std::allocator> Ttb;  

    C<std::allocator> b; 

    D<Ttb> c(b); 
} 
+0

このコードを見ると、私はすべて混乱していますが、これがうまくいくのはうれしいです。理由は分かりません... –

+0

@rxu - それはテンプテーション化のもう一つのレベルです。 'D'のテンプレート引数は、型ではなくテンプレートテンプレートである引数を持つテンプレート型です。ですから、 'D'のテンプレート引数は(この式を使用することができれば)テンプレートテンプレート引数を持つテンプレートテンプレートテンプレートです。私の例(専門分野)は、 'D'の引数のtemplate-template引数を抽出する方法を示しています。それは明確ではないのですか? :( – max66

+0

私はこれを今得ます。ありがとう。 –

関連する問題