数组和右值
$4.2/1 - “类型的左值或右值 “N T 数组”或“未知数组” T 的界限”可以转换为 “指向 T 的指针”类型的右值。这 结果是指向第一个的指针 数组的元素。”
我不确定除了在初始化/声明期间之外如何获取数组类型的右值?
$4.2/1 - "An lvalue or rvalue of type
“array ofN T” or “array of unknown
bound of T” can be converted to an
rvalue of type “pointer to T.” The
result is a pointer to the first
element of the array."
I am not sure how do we get an rvalue of an array type other than during initialization/declaration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这有机会展示数组右值吗?
Would this stand a chance to demonstrate Array Rvalue?
我不确定您在这种情况下所说的“初始化/声明”指的是什么。下面,该数组是纯右值,
这可以通过类型为{1, 2, 3}) 进行验证代码>.以这种方式动态创建数组最初并不是为了工作,而是通过统一初始化的相关工作溜进了工作草案。当我意识到 C++0x 工作草案中的某些段落不允许这种动态创建临时数组的某些特殊情况,而其他段落则允许时,我向 C++ 委员会发送了一份缺陷报告,然后该委员会根据GCC 部分工作实施决定全力支持这一点。
int[3]
decltype(aliasI'm not sure what you refer to by "initialization/declaration" in this context. In the following, the array is a prvalue
This can be verified by
decltype(alias<int[]>{1, 2, 3})
having the typeint[3]
. Creating arrays this way on the fly wasn't initially intended to work but slipped into the working draft by-the-way of related work on uniform initialization. When I realized that some paragraphs in the C++0x working draft disallow some special case of this on-the-fly creation of array temporaries while other paragraphs allow it, I sent a defect report to the C++ committee, which then on the basis of GCC's partially working implementation decided to fully support this.您无法获取数组类型的右值。数组只能是左值,每当它们在左值中使用时,它们就会衰减为指向第一个元素的指针。
[1] 中的表达式
array
是int (&)[10]
类型的左值,它被转换为int *p
类型的右值code>,即 N==10 T==int 的右值数组被转换为指向 T==int 的指针类型的左值。You cannot get an rvalue of array type. Arrays can only be lvalues, and whenever they are used in an lvalue they decay to a pointer to the first element.
The expression
array
in [1] is an lvalue of typeint (&)[10]
that gets converted to an rvalue of typeint *p
, that is, the rvalue array of N==10 T==int is converted to an lvalue of type pointer to T==int.获取数组正确的引用值非常容易,因为类引用属性将添加到其成员中。
It's very easy to get array right reference value, for a class reference property will be added to its members.