C++ typedef typename classname :: template

bta*_*tan 6 c++ templates

我无法解析以下代码行的含义:

typedef typename Allocator::template rebind<Mapped>::other mapped_type_allocator;
Run Code Online (Sandbox Code Playgroud)

这是分配器重新绑定的代码(https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-api-4.5/a00756_source.html的第63行 )

这与以下有什么不同?

typedef typename Allocator::rebind<Mapped>::other mapped_type_allocator;
Run Code Online (Sandbox Code Playgroud)

Adr*_*chi 6

typedef typename Allocator::template rebind<Mapped>::other mapped_type_allocator;
Run Code Online (Sandbox Code Playgroud)

这是一个模板化的typedef - 它建立mapped_type_allocator为模板的别名.


typedef typename Allocator::rebind<Mapped>::other mapped_type_allocator;
Run Code Online (Sandbox Code Playgroud)

这是类型的typedef.要编译好,Mapped需要定义/已知.


Allocator::rebind<typename X>::other(作为一个概念)有望定义模板,而不是一种类型.


M.M*_*M.M 6

在这里,我在单独的行中显示此声明的分组:

typedef                                                    mapped_type_allocator;
        typename Allocator::                       ::other 
                            template rebind<Mapped>
Run Code Online (Sandbox Code Playgroud)

关键字typenametemplate后面的空格可能会让您感到困惑。对于使用这两个关键字的原因,请参阅我必须将“模板”和“类型名称”关键字放在哪里以及为什么要放?.