我无法解析以下代码行的含义:
typedef typename Allocator::template rebind<Mapped>::other mapped_type_allocator;
这是分配器重新绑定(bind)的代码(第 63 行 https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-api-4.5/a00756_source.html )
这与下面的有何不同?
typedef typename Allocator::rebind<Mapped>::other mapped_type_allocator;
最佳答案
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
(作为一个概念)应该定义一个模板,而不是一个类型。
关于C++ typedef typename 类名::模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40035282/