这个表达式是左值还是右值?
Is this expression an lvalue or an rvalue?
看看这个表达式:
T t;
T& ref = t;
ref
表达式是 lvalue
还是 rvalue
? 我相信它是 rvalue
因为 ref
不 "designates a function or an object":
"An lvalue (so called, historically, because lvalues could appear on
the left-hand side of an assignment expression) designates a function
or an object."
[开放标准草案 n3092]
根据 cppreference,引用不是对象。
"The following entities are not objects: value, reference [...]"
我有疑问,因为 ref
在 =
的左边。
引用确实指定了函数或对象!标准里就是这么写的!参见 [expr.type]/1:
If an expression initially has the type “reference to T” ([dcl.ref], [dcl.init.ref]), the type is adjusted to T prior to any further analysis.
The expression designates the object or function denoted by the reference,[...]
I'm in doubt, because ref is in the left side of =.
ref
是一个名称,因此是一个左值。
I believe it's an rvalue because ref does not "designates a function or an object"
它指定与 t
相同的对象。
看看这个表达式:
T t;
T& ref = t;
ref
表达式是 lvalue
还是 rvalue
? 我相信它是 rvalue
因为 ref
不 "designates a function or an object":
"An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignment expression) designates a function or an object."
[开放标准草案 n3092]
根据 cppreference,引用不是对象。
"The following entities are not objects: value, reference [...]"
我有疑问,因为 ref
在 =
的左边。
引用确实指定了函数或对象!标准里就是这么写的!参见 [expr.type]/1:
If an expression initially has the type “reference to T” ([dcl.ref], [dcl.init.ref]), the type is adjusted to T prior to any further analysis. The expression designates the object or function denoted by the reference,[...]
I'm in doubt, because ref is in the left side of =.
ref
是一个名称,因此是一个左值。
I believe it's an rvalue because ref does not "designates a function or an object"
它指定与 t
相同的对象。