gpt4 book ai didi

c++ - 为什么 [expr.ref]/2 下面的纯右值?

转载 作者:行者123 更新时间:2023-11-27 23:55:22 26 4
gpt4 key购买 nike

[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] 将左值转换为右值。因此,纯右值相当普遍且容易获得。

关于c++ - 为什么 [expr.ref]/2 下面的纯右值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43007483/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com