Article From:https://www.cnblogs.com/yaoyudadudu/p/9216924.html

I used to think that the left value is the value on the left side of the sign, and the right value is the value on the right side of the equal sign.

I

Too naive

Original address: https://blog.csdn.net/hyman_yx/article/details/52044632 (intrusion delete)

——————–I am the text segmentation line – — – — – —-

left value”, “right value”

In C++ 11, all values must belong to one of the left and right values, and the right values can be subdivided into pure right values and dead values.In C++ 11, where the address can be taken, the name is the left value. On the contrary, the right value can be taken without the address.For example, int a = b+c, a is the left value, its variable name is a, through & a can get the address of the variable; the return value of the expression b+c, the function int func () is the right value, before it is assigned to a variable, we can not pass the variable name.Find it, and (b+c) such an operation will not be compiled.

C++98The middle right value is the pure right value, and the pure right value refers to the literal value of the temporary variable value and the object value which is not associated with the object.A temporary variable is the return value, expression, and so on, such as the return value of the function int func (), the expression a+b; the literal value that is not associated with the object, such as true, 2, “C” and so on.

C++11The right value in C++98 is expanded.In C++ 11, the right value is divided into pure right value (prvalue, Pure Rvalue) and the death value (xvalue, eXpiring Value).The concept of pure right value is equivalent to our concept of the right value in the C++98 standard, which refers to the literal values of temporary variables and those that are not associated with objects.The value of death is a new expression that is related to the right value reference of C++11, so that the expression is usually the object to be moved.,For example, return the right value to refer to T& & the return value of function, the return value of std:: move, or convert to T& & the return value of type conversion function.

PerishIt can be understood that the value is obtained by stealing other variables’ memory space. In ensuring that other variables are no longer used, or are about to be destroyed, the release and distribution of memory space can be avoided by “stealing”, and the life period of variable values can be extended.

lvalue referenceIt is the type of reference to a left value.rvalue referenceIt is a type that is referenced by a right value. In fact, because the right value usually does not have a name, we can only find its existence by way of reference.

rvalue referenceandlvalue referenceAll of them belong to the type of reference. Whether it is declaring a left value or a right value reference, it must be initialized immediately. The reason is that the reference type itself does not own the memory of the bound object, but is an alias of the object. The left value reference is an alias of the named variable value, while the right value reference is.It is an alias of an anonymous (anonymous) variable.

lvalue referenceIt is not usually bound to the right value, butConstant left value referenceIt is a “omnipotent” type of reference. It can accept very low value, constant left value and right value to initialize it. However, the right value quoted by the constant left value can only be read-only in its “remaining life”. Relatively, a very low value can only be initialized by a very low value.

Leave a Reply

Your email address will not be published. Required fields are marked *