c++ - 这个表达式是左值还是右值?

标签 c++ c++11 move-semantics rvalue

看看这个表达式:

T t;    
T& ref = t;

ref 表达式是左值还是右值我相信它是右值 因为 ref 没有“指定函数或对象”:

"An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignment expression) designates a function or an object."

[开放标准草案 n3092]

根据 cppreference , 引用不是对象。

"The following entities are not objects: value, reference [...]"

我有疑问,因为 ref= 的左侧。

最佳答案

I'm in doubt, because ref is in the left side of =.

ref 是一个名称,因此也是一个左值。

I believe it's an rvalue because ref does not "designates a function or an object"

它指定与 t 相同的对象。

关于c++ - 这个表达式是左值还是右值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56116361/

相关文章:

c++ - 如何将 C++11 随机数生成器传递给函数?

C++制作控制台: binding a function

c++ - c++中的引用解释

c++ - 具有静态绑定(bind)成员函数指针的可变参数模板的多个特化?

c++ - 为什么我需要在 move 构造函数的初始化列表中使用 std::move?

c++ - 64 位整数和旧的 C++ 编译器

带有 json 文件的 C++ Boost 程序选项

带有列表初始化的 C++11 嵌套映射

c++ - 这是对 move 语义的滥用/误用吗?

C++11 - move 语义在构造上很慢