C++ typedef typename 类名::模板

标签 c++ templates

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

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/

相关文章:

c++ - 使用 Qt 制作静态构建(独立应用程序)

c++ - std::bind 参数复制行为

c++ - 对象 vector 的模板字符串表示

c++ - constexpr if 和 static_assert

c++ - 绝对安全的静态/运行时数字转换

c++ - 如何使用 dlib C++ 库编写基于套接字的应用程序?

c++ - 在 Windows 8 中禁用 CUDA 的 TDR

c++ - 为什么在缺少非 const 虚方法时不能实例化类的 const 实例?

c++ - C++ 标准中 14.8.2 第 3 段和第 4 段的含义是什么?

c++ - 使用绝对指针地址作为模板参数