【发布时间】:2012-10-31 08:36:41
【问题描述】:
考虑以下代码:
#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) 中的括号不是创建一个未命名的(r 值)表达式,然后递增吗?
【问题讨论】:
-
不,你是不是把它和
f(x)和f((x))不同的其他语言混淆了? -
@BoPersson 但是在某些情况下它会有所不同。例如
decltype(x)和decltype((x))可以不同。 -
@juanchopanza:该死的......这很棘手!
标签: c++ parentheses rvalue