问题描述
假设我有一些 stl 容器类 obj 的对象.我可以通过这种方式定义其他相同类型的对象:
decltype(obj) obj2;但我不能以这种方式为容器声明迭代器:
decltype(obj)::iterator it = obj.begin();为什么?我做错了什么吗?
根据最终的 C++0x 草案 (FDIS),您的代码格式良好.这是 Visual Studio 编译器尚未实现的后期更改.
与此同时,一种解决方法是使用 typedef:
typedef decltype(obj) obj_type;obj_type::iterator it = obj.begin();相关章节和诗句是5.1.1/8:
<前>合格 ID:[...]nested-name-specifier 模板opt unqualified-id嵌套名称说明符:[...]声明类型说明符 ::声明类型说明符:decltype ( 表达式 )为了完整起见:
原始核心问题
措辞建议
Say I have an object of some of stl container classes obj. I can define other object of same type this way:
decltype(obj) obj2;
But I can't declare iterator for the container this way:
decltype(obj)::iterator it = obj.begin();
Why? Am I doing something wrong?
Your code is well-formed according to the final C++0x draft (FDIS). This was a late change that's not yet been implemented by the Visual Studio compiler.
In the meantime, a workaround is to use a typedef:
typedef decltype(obj) obj_type;
obj_type::iterator it = obj.begin();
EDIT: The relevant chapter and verse is 5.1.1/8:
qualified-id:
[...]
nested-name-specifier templateopt unqualified-id
nested-name-specifier:
[...]
decltype-specifier ::
decltype-specifier:
decltype ( expression )
And for completeness's sake:
The original core issue
Proposal for wording
这篇关于decltype 的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)