【问题标题】:What is the type of a named rvalue reference?命名右值引用的类型是什么?
【发布时间】:2011-07-28 18:38:35
【问题描述】:

考虑以下代码:

int&& x = 42;
static_assert(std::is_same<decltype( x ), int&&>::value, "&&");
static_assert(std::is_same<decltype((x)), int& >::value, "&" );

那么,x 的类型是什么?是int&amp;&amp; 还是int&amp;

(我在阅读this answer后问自己这个问题。)

【问题讨论】:

    标签: c++ c++11 rvalue-reference decltype


    【解决方案1】:

    x(变量)的类型是int&amp;&amp;。所以decltype(x) 产生int&amp;&amp;。表达式x 的类型是int。如果表达式是左值,decltype((x)) 会生成对表达式类型的左值引用。所以decltype((x)) 产生int&amp;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-26
      相关资源
      最近更新 更多