C ++ 11左值到右值转换? [英] C++11 lvalue-to-rvalue conversion?
问题描述
我认为我缺少有关左值到右值标准转换的基本知识。
I think I'm missing something basic regarding the lvalue-to-rvalue standard conversion.
从C ++ 11 4.1开始:
From C++11 4.1:
非函数,非数组类型T的glvalue可以转换为prvalue
A glvalue of a non-function, non-array type T can be converted to a prvalue
所以我们声明一个变量 x
:
So we declare a variable x
:
int x = 42;
此范围中的表达式 x
现在一个左值(也是一个左值)。它满足4.1中从左值到右值转换的要求。
An expression x
in this scope is now an lvalue (so also a glvalue). It satisfies the requirements in 4.1 for an lvalue-to-rvalue conversion.
将左值到右值转换应用于上下文的典型示例是什么?表达式 x
?
What is a typical example of a context where the lvalue-to-rvalue conversion is applied to the expression x
?
推荐答案
一个prvalue( pure rvalue)为标识临时对象(或其子对象)或不与任何对象相关联的值的表达式。
A prvalue ("pure" rvalue) is an expression that identifies a temporary object (or a subobject thereof) or is a value not associated with any object.
struct Bar
{
int foo()
{
int x = 42;
return x; // x is converted to prvalue
}
};
表达式 bar.foo()
是 prvalue 。
OR
Lambda表达式,例如
Lambda expressions, such as
[](int x){return x*x;}
§3.10.1
prvalue(纯 rvalue)是一个非xvalue的rvalue。 [示例:调用返回类型不是引用的函数的结果是prvalue 。文字的值(例如12、7.3e5或true)也是prvalue。 —结束示例]
A prvalue ("pure" rvalue) is an rvalue that is not an xvalue. [ Example: The result of calling a function whose return type is not a reference is a prvalue. The value of a literal such as 12, 7.3e5, or true is also a prvalue. —end example ]
请参见 n3055 。
这篇关于C ++ 11左值到右值转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!