C++ typedef typename classname::template
C++ typedef typename classname::template
我无法解析下面这行代码的含义:
typedef typename Allocator::template rebind<Mapped>::other mapped_type_allocator;
这是分配器重新绑定的代码(第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;
这是一个模板化的类型定义——它将mapped_type_allocator
建立为模板的别名。
typedef typename Allocator::rebind<Mapped>::other mapped_type_allocator;
这是一个类型的typedef。要编译成功,需要定义/知道Mapped
。
Allocator::rebind<typename X>::other
(作为一个概念)被期望定义一个模板,而不是一个类型
这里我展示了这个声明在不同行的分组:
typedef mapped_type_allocator;
typename Allocator:: ::other
template rebind<Mapped>
关键字typename
和template
后面有空格,这可能会使您感到困惑。关于使用这两个关键字的原因,请参阅我必须在哪里以及为什么要放置"模板"。和";typename"关键字?.
相关文章:
- 表示"accepting anything for this template argument" C++概念的通配符
- 传递给std::function template的template参数究竟代表什么
- 在template中使用std::variant的template函数
- 如何修复此错误:className::className的无效使用
- 枚举类'classname'的多重定义
- C++ template for QList
- C++ - 为什么这里需要'template'关键字?
- 使用"std::enable_if_t" "function template has already been defined"
- C++模板错误:"invalid explicitly-specified argument for template parameter"
- C++ class template
- 在"template"和函数声明之间使用:template<typename trait> using tr = base_trait<trait> void fn(tr::t
- 为什么编译器说"candidate template ignored: couldn't infer template argument 'InputIterator'"?
- 为什么在这种情况下我需要 .template
- std::span constructor, libcxx vs libstdc++, template vs non-
- 模板函数参数到模板函数的"candidate template ignored: could not match ..."
- MacOS 上的 LLVM - 标准文件 iosfwd 中未知类型名称'template'
- std::get like (partial) template specialization
- 实现多类型算术运算符时如何解决"template argument deduction/substitution failure"
- 更新 Visual Studio 2017,现在出现编译错误 C7510:"回调":使用依赖模板名称必须以 'template' 为前缀
- C++ typedef typename classname::template