为什么 [expr.ref]/2 中的纯右值?
Why the prvalue below in [expr.ref]/2?
For the first option (dot) the first expression shall be a glvalue
having complete class type. For the second option (arrow) the first
expression shall be a prvalue having pointer to complete class type.
The expression E1->E2 is converted to the equivalent form (*(E1)).E2;
the remainder of [expr.ref] will address only the first option
(dot).68 In either case, the id-expression shall name a member of the
class or of one of its base classes. [ Note: Because the name of a
class is inserted in its class scope (Clause [class]), the name of a
class is also considered a nested member of that class. — end note ]
[ Note: [basic.lookup.classref] describes how names are looked up
after the . and -> operators. — end note ]
在下面的代码片段中,p->f()
是一个 后缀表达式 而 p
是一个左值。
struct A{ void f(){} };
A *p = new A;
int main(){
p->f();
}
每当需要纯右值但给出了左值时,可以通过左值到右值转换 [conv.lval] 将左值转换为右值。因此纯右值相当普遍且容易获得。
For the first option (dot) the first expression shall be a glvalue having complete class type. For the second option (arrow) the first expression shall be a prvalue having pointer to complete class type. The expression E1->E2 is converted to the equivalent form (*(E1)).E2; the remainder of [expr.ref] will address only the first option (dot).68 In either case, the id-expression shall name a member of the class or of one of its base classes. [ Note: Because the name of a class is inserted in its class scope (Clause [class]), the name of a class is also considered a nested member of that class. — end note ] [ Note: [basic.lookup.classref] describes how names are looked up after the . and -> operators. — end note ]
在下面的代码片段中,p->f()
是一个 后缀表达式 而 p
是一个左值。
struct A{ void f(){} };
A *p = new A;
int main(){
p->f();
}
每当需要纯右值但给出了左值时,可以通过左值到右值转换 [conv.lval] 将左值转换为右值。因此纯右值相当普遍且容易获得。