2016-10-14 16 views
4

私は次のコード行の意味を解析することはできませんよ。C++のtypedef typenameにクラス名::テンプレート

typedef typename Allocator::template rebind<Mapped>::other mapped_type_allocator; 

これは、アロケータの再バインド( https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-api-4.5/a00756_source.htmlのライン63)

のコードですこれは次の点とどのように違うのですか?

typedef typename Allocator::rebind<Mapped>::other mapped_type_allocator; 

答えて

5
typedef typename Allocator::template rebind<Mapped>::other mapped_type_allocator; 

これはtemplated typedefある - それは、テンプレートの別名としてmapped_type_allocator確立します。


typedef typename Allocator::rebind<Mapped>::other mapped_type_allocator; 

これは、型のtypedefです。 OKをコンパイルするには、Mappedを定義しておく必要があります。


Allocator::rebind<typename X>::other(概念として)は、テンプレート、ないタイプを定義することが期待されます。ここで

2

私は別の行にこの宣言のグループ化を示しています。

typedef             mapped_type_allocator; 
     typename Allocator::      ::other 
          template rebind<Mapped> 

キーワードtypenametemplateがあなたを混同している可能性があり、それらの後にスペースを持っています。その2つのキーワードが使用された理由で、Where and why do I have to put the "template" and "typename" keywords?を参照してください。

+0

私は視覚的表現が好きです。 +1 – skypjack

関連する問題