George2 wrote:
I do not know how in the following code, rvalue -- return of X(),
could result in a lvalue finally and binded to a non-const reference
input parameter of function f.
You're confusing the return type of 'X()' and the full expression
that you can see inside the parentheses where 'f' is called.
>
Any ideas?
-
struct X {
-
};
-
void f (X& x) {}
-
int main()
-
{
-
f (X() = X());
-
return 0;
-
}
-
The trick here is based on the fact that every temporary of a class
type is a separate object, for which you can call member functions.
The operator= is a member function. What is its usual signature?
Rewrite the expression
f( X() = X() )
in terms of member function calls, and you will hopefully see how
an r-value can be turned into an l-value.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask