C++ typedef typename classname::template [英] C++ typedef typename classname::template

查看:41
本文介绍了C++ typedef typename classname::template的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am not able to parse the meaning of the following line of code:

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

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

This is the code for allocator rebinding (line 63 of 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;

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

This is a templated typedef - it establishes mapped_type_allocator as an alias for a template.

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

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

This is a typedef for a type. To compile OK, the Mapped would need to be defined/known.

Allocator::rebind::other(作为一个概念)应该定义一个模板,而不是一个类型.

The Allocator::rebind<typename X>::other (as a concept) is expected to define a template, not a type.

这篇关于C++ typedef typename classname::template的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆