左值/右值是表達式的值的屬性,不是類型的屬性,不與類型一一對應。它是由表達式的值的類型,與表達式的形式(得到這個值的過程)共同決定的。//42的類型是int,這是一個int字面量,因而是右值int&&rri=42;inta=42;//a的類型也是int,但它是一個變量,因而是左值int&&rri2=a;//ERROR//a+1的類型還是int,它是+運算符的結果,為右值int&&rri3=a+1;rri本身作為一個表達式,是一個左值。單獨由一個變量組成的表達式叫做id-expression(unqualified-id)。unqualified-id為函數(shù)、變量、類成員變量結果為左值;其它為右值(比如enumerator)。rri是一個變量,結果為左值。8.1.4.1Unqualifiednames1)......Theexpressionisanlvalueiftheentityisafunction,variable,ordatamemberandaprvalueotherwise;......static_cast(rri)的類型雖然與rri相同,但是它是一個右值。static_cast(v),僅當T為左值引用或對函數(shù)的右值引用時,結果為左值。其余情況均為右值。8.2.9Staticcast1)Theresultoftheexpressionstatic_cast(v)istheresultofconvertingtheexpressionvtotypeT.IfTisanlvaluereferencetypeoranrvaluereferencetofunctiontype,theresultisanlvalue;ifTisanrvaluereferencetoobjecttype,theresultisanxvalue;otherwise,theresultisaprvalue.......C++標準里對每一種表達式形式,都詳細定義結果何時為左值、何時為右值。引用來自C++17draftn4659