微软官网解释
示例
glvalue
g是generalize的意思,glvalue是个形象的概念,是lvalue和xvalue的并集
lvalue
左值字面意思是能够放在右边的值,包含成员变量和能返回一个左值的函数
int main()
{
int i, j, *p;
// Correct usage: the variable i is an lvalue and the literal 7 is a prvalue.
i = 7;
// Incorrect usage: The left operand must be an lvalue (C2106).`j * 4` is a prvalue.
7 = i; // C2106
j * 4 = 7; // C2106
// Correct usage: the dereferenced pointer is an lvalue.
*p = i;
// Correct usage: the conditional operator returns an lvalue.
((i < 3) ? i : j) = 7;
// Incorrect usage: the constant ci is a non-modifiable lvalue (C3892).
const int ci = 7;
ci = 9; // C3892
}
xvalue
x是expiring,xvalue意思是行将走完生命周期的值,xvalue有地址但程序无奈进入,例如函数返回右值援用的表达式,或者应用move语句这类传入的参数,这种参数快死掉了,就叫做xvalue,例如1 + 1, move(a), static_cast<>({xvalue})
rvalue
右值能够是纯右值,也能够是xvalue
prvalue
不是xvalue的右值,即没有地址且程序无奈进入,例如字符,函数返回的非援用类型
发表回复