【发布时间】:2012-12-13 06:49:34
【问题描述】:
我刚开始通过阅读this page 了解 c++11 中的右值引用,但我被困在了第一页。这是我从该页面获取的代码。
int& foo();
foo() = 42; // ok, foo() is an lvalue
int* p1 = &foo(); // ok, foo() is an lvalue
int foobar();
j = foobar(); // ok, foobar() is an rvalue
int* p2 = &foobar(); // error, cannot take the address of an rvalue
- 为什么
foo()是左值?是不是因为foo()返回的int&基本上是一个左值? - 为什么
foobar()是右值?是因为foobar()返回int吗? - 一般来说,您为什么要关心函数是否为右值?我想如果我阅读了那篇文章的其余部分,我会得到答案。
【问题讨论】: