Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么用括号包装的标记不是r值表达式?_C++_Parentheses_Rvalue - Fatal编程技术网

C++ 为什么用括号包装的标记不是r值表达式?

C++ 为什么用括号包装的标记不是r值表达式?,c++,parentheses,rvalue,C++,Parentheses,Rvalue,考虑以下代码: #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 { Foo():条(0){} int-bar; }; i

考虑以下代码:

#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
{
Foo():条(0){}
int-bar;
};
int main()
{
富富,;
++(富吧);

标准::cout,因为标准在3.4.2第6段中明确规定:

带括号的表达式是一个主表达式,其类型和 值与所附表达式的值相同。存在 括号的大小不影响表达式是否为左值。


强调我。

不,括号除了改变操作顺序外没有任何意义


要创建右值,您需要使用特殊函数
std::move(x)

不,您是否将其与
f(x)
f((x))
不同的其他语言相混淆?@BoPersson但在某些上下文中它会产生不同。例如
decltype(x)
decltype((x))
可以不同。@juanchopanza:该死的……这很棘手!我很困惑,因为:
struct Widget{}w;
->
decltype(w)
decltype((w))
不一样。另请参见幻灯片33。@user1787909:
decltype
是特殊的。您可能想在此基础上创建一个新的stackoverflow问题。在这里取消命名有这么难吗?adl=依赖参数的名称查找为了改进stackoverflow数据库,我不再回答注释问题。