Is the temporary object be a rvalue?

As mentioned in this tutorial(http://msdn.microsoft.com/en-us/library/f90831hc.aspx), a temporary object is a rvalue.

I write a sample code:

1
2
3
4
5
6
7
8
9
10
11
class A{};
A retA() {return A();}
int main()
{
    retA() = A(); // no compile error in MS VS2012 and GCC 4.8.1
    return 0;
}

I think that "retA()" must return a temporary object, but, in this sample code, it is used as a lvalue.

why? can anyone help me? thanks.
They do not say that a temporary object is an rvalue. Objects do not have value categories, that's a property of expressions. There's a slightly more detailed (I hope) exposition at
http://en.cppreference.com/w/cpp/language/value_category

The expression retA() is indeed an rvalue expression (because it is a function call expression to a value-returning function).

In the expression retA() = A(), it is not used as a lvalue. To use it as lvalue, try to take its address: &retA()
Last edited on
thank you for your kindly reply. :)
Topic archived. No new replies allowed.