Value categories
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
當一個C + +表達式(操作符與它的參數)進行評估,其結果是一些非引用類型的值。每個表達式的主要價值類別的一個.
Original:
When a C++ expression (an operator with its arguments) is evaluated, it results in a value of some non-reference type. Each expression belongs to exactly one of the primary value categories.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目錄 |
[编辑] 主要類別
[编辑] 左值
「左值」是一個表達式,用於標識一個非臨時對象或一個非成員函數.
Original:
An lvalue is an expression that identifies a non-temporary object or a non-member function.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
下面的表達式是左值
Original:
The following expressions are lvalues:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- 範圍內的對象或函數的名稱,無論類型,如
std::cin或std::endl。即使對象的類型是右值引用,表達它的名字是一個左值表達式.Original:The name of an object or function in scope, regardless of type, such asstd::cinorstd::endl. Even if the object's type is rvalue reference, the expression consisting of its name is an lvalue expression.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 函數調用操作符表達式的功能或操作者的返回類型是一個左值引用,如
std::getline(cin, str)或cout << 1或或++n或*pOriginal:Function call or operator expression if the function's or operator's return type is an lvalue reference, such asstd::getline(cin, str)orcout << 1oror++nor*pThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 強制轉換表達式的左值的引用類型.Original:Cast expression to lvalue reference type.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 如果函數的返回類型的函數調用表達式的右值引用功能類型(罕見)Original:Function call expression if the function's return type is rvalue reference to function type (rare)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - CAST表達式的右值引用的功能.Original:Cast expression to rvalue reference to function.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
屬性
Original:
Properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- 同glvalue(如下圖)Original:Same as glvalue (below)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 一個左值的地址可以採取:
&++i和&std::endl是有效的表達式.Original:Address of an lvalue may be taken:&++iand&std::endlare valid expressions.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 修改的左值,可以使用內置的賦值運算符的第一個參數(左).Original:A modifiable lvalue may be used as the first (left) argument of the built-in assignment operator.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 一個lvalue可用於初始化左值參考,這由表達式識別的對象的一個新的名字而相關聯.Original:An lvalue may be used to 初始化左值參考; this associates a new name with the object identified by the expression.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 右值NJ/ prvalueNJ
A「prvalue」是一個表達式,用於標識一個臨時對象(或子對象除外),或不與任何對象關聯的值.
Original:
A prvalue is an expression that identifies a temporary object (or a subobject thereof) or is a value not associated with any object.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
下面的表達式prvalues
Original:
The following expressions are prvalues:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- 文字,如42或true或nullptr.Original:Literal, such as 42 or true or nullptr.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 如果函數調用/操作符表達式的功能或操作人員的返回類型是不是一個引用,如
str.substr(1, 2)或2+2Original:Function call/operator expression if the function's or the operator's return type is not a reference, such asstr.substr(1, 2)or2+2The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - CAST表達式引用類型以外的其他任何類型.Original:Cast expression to any type other than reference type.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Lambda表達式,如 [](int x){return x*x;}Original:Lambda expressions, such as [](int x){return x*x;}The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
屬性
Original:
Properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- 同右值(如下圖)Original:Same as rvalue (below)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 一個prvalue不能是多態對象的動態類型,它確定類型的表達式.Original:a prvalue cannot be polymorphic: the dynamic type of the object it identifies is always the type of the expression.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 不能被const限定非類prvalue的.Original:a non-class prvalue cannot be const-qualified.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[编辑] xvalueNJ
一個 xvalue「,用於標識一個」屆滿「對象的,即,從可移動的對象,該對象是一個表達式。可能是一個無名的臨時標識的對象由一個xvalue的表達,它可能是一個命名對象,範圍,或任何其他類型的對象,但如果作為函數的參數,xvalue將始終綁定到右值引用過載,如果有的話.
Original:
An xvalue is an expression that identifies an "expiring" object, that is, the object that may be moved from. The object identified by an xvalue expression may be a nameless temporary, it may be a named object in scope, or any other kind of object, but if used as a function argument, xvalue will always bind to the rvalue reference overload if available.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
只有以下的表達式是xvalues:
Original:
Only the following expressions are xvalues:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- 一個函數調用表達式,如果函數的返回類型是一個右值引用的對象類型,如
std::move(val)Original:A function call expression, if the function's return type is an rvalue reference to object type, such asstd::move(val)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 一個右值引用的對象類型強制轉換表達式,如
static_cast<T&&>(val)或(T&&)valOriginal:A cast expression to an rvalue reference to object type, such asstatic_cast<T&&>(val)or(T&&)valThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 類的非靜態成員訪問表達式,其中的對象表達式的值為xValueOriginal:a non-static class member access expression, in which the object expression is an xvalueThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 在第一個操作數的指針成員表達是xValue和第二個操作數是一個指向數據成員的指針.Original:A pointer-to-member expression in which the first operand is an xvalue and the second operand is a pointer to data member.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
屬性
Original:
Properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- 同右值(如下圖)Original:Same as rvalue (below)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 同glvalue(如下圖)Original:Same as glvalue (below)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
像prvalues,xvalues綁定到右值引用,,但不像prvalues,值為xValue,可能是多態的,非類值為xValue可能是合格的CV-.
Original:
Like prvalues, xvalues bind to rvalue references, but unlike prvalues, an xvalue may be polymorphic, and a non-class xvalue may be cv-qualified.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 混合類
[编辑] glvalueNJ
一個glvalue是一個表達式,它是一個左值,或一個xvalue的.
Original:
A glvalue is an expression that is either an lvalue or an xvalue.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
屬性
Original:
Properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- 一個glvalue可以隱式轉換為左值,右值,數組與指針,或函數指針隱式轉換prvalue.Original:A glvalue may be implicitly converted to prvalue with lvalue-to-rvalue, array-to-pointer, or function-to-pointer 隱式轉換.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 一個glvalue可能是多態的動態類型的對象,它標識不一定是靜態類型的表達式.Original:A glvalue may be polymorphic: the dynamic type of the object it identifies is not necessarily the static type of the expression.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 右值NJ
右邊的值可以是一個表達式,它可以是一個prvalue或值為xValue.
Original:
An rvalue is an expression that is either a prvalue or an xvalue.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
屬性(注意,這些適用於都的xvalues和prvalues,這意味著它們適用於前C + +11的右值以及)
Original:
Properties (note, these apply to both xvalues and prvalues, which means they apply to the pre-C++11 rvalues as well)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- 一個rvalue的地址可能不會採取
&i++和&42和&std::move(val)是無效的.....Original:Address of an rvalue may not be taken:&i++and&42and&std::move(val)are invalid.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 可以使用一個rvalue初始化一個常量左值引用,在這種情況下,由右值標識的對象的壽命延長,直到參考端的範圍.Original:An rvalue may be used to 初始化一個常量左值引用, in which case the lifetime of the object identified by the rvalue is extended until the scope of the reference ends.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 可以使用一個rvalue初始化一個右值引用,在這種情況下,由右值標識的對象的壽命延長,直到參考端的範圍.Original:An rvalue may be used to 初始化一個右值引用, in which case the lifetime of the object identified by the rvalue is extended until the scope of the reference ends.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 當作為函數的參數時,兩個重載的函數的情況下,一個右值引用參數和其他左值const參數,右值綁定到右值引用過載(因此,如果複製和移動的構造是,右值參數調用移動的構造函數,同樣的複製和移動賦值運算符).Original:When used as a function argument and when two overloads of the function are available, one taking rvalue reference parameter and the other taking lvalue reference to const parameter, rvalues bind to the rvalue reference overload (thus, if both copy and move constructors are available, rvalue arguments invoke the 移動的構造函數, and likewise with copy and move assignment operators).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 特殊類別
[编辑] 的成員函數調用之前
表達obj.*mfp和ptr->*mfp地方
mfp是一個指向成員函數的指針,分類prvalue的表達,但他們可以不被使用,以初始化引用,作為函數的參數,或為任何目的,在所有,除非在左側的參數的函數,調用表達式,例如: (pobj->*ptr)(args).Original:
The expressions obj.*mfp and ptr->*mfp where
mfp is a pointer to member function, are classified as prvalue expressions, but they cannot be used to initialize references, as function arguments, or for any purpose at all, except as the left-hand argument of a function call expression, e.g. (pobj->*ptr)(args).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 無效的表達
函數調用表達式返回void,投的表達式來void,和扔表達式被列為prvalue的表達,但它們不能被用來初始化引用或作為函數的參數。它們可以被用來在一個廢棄價值的情況下(例如,在一個屬於自己的行,左邊的參數的逗號操作符等),並在return聲明一個函數返回void。拋出表達式(但並非其他的空隙prvalues)此外,也可以使用作為第二個和第三個操作數的條件運算符?.
Original:
Function call expressions returning void, cast expressions to void, and throw-expressions are classified as prvalue expressions, but they cannot be used to initialize references or as function arguments. They can be used in a discarded-value context (e.g. on a line of its own, as the left argument of the comma operator, etc) and in the return statement in a function returning void. In addition, throw-expressions (but not other void prvalues) may be used as the second and the third operands of the 條件運算符?.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.