gpt4 book ai didi

c++ - 为什么用括号包裹的标记不是 r 值表达式?

转载 作者:可可西里 更新时间:2023-11-01 15:18:16 24 4
gpt4 key购买 nike

考虑以下代码:

#include <iostream>

struct Foo
{
Foo() : bar( 0 ) {}

int bar;
};


int main()
{
Foo foo;

++(foo.bar);

std::cout<< foo.bar << std::endl;

system("pause");
return 0;
};

为什么 foo.bar 的计算结果为 1?

(foo.bar) 中的括号是否创建了一个未命名的(右值)表达式,然后递增?

最佳答案

因为标准在 3.4.2 第 6 段中明确指出:

A parenthesized expression is a primary expression whose type and value are identical to those of the enclosed expression. The presence of parentheses does not affect whether the expression is an lvalue.

强调我的。

关于c++ - 为什么用括号包裹的标记不是 r 值表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13153993/

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