c – decltype的行为
发布时间:2020-12-16 05:50:02 所属栏目:百科 来源:网络整理
导读:说我有一些stl容器类obj的对象.我可以这样定义相同类型的其他对象: decltype(obj) obj2; 但是我不能通过这种方式为容器声明迭代器: decltype(obj)::iterator it = obj.begin(); 为什么?我做错了吗? 解决方法 根据最终的C 0x草案(FDIS),您的代码格式良好.
|
说我有一些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:
qualified-id:
[...]
nested-name-specifier templateopt unqualified-id
nested-name-specifier:
[...]
decltype-specifier ::
decltype-specifier:
decltype ( expression )
为了完整起见: The original core issue Proposal for wording (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
