S
subramanian100in
Consider the following:
int x;
int y;
int z;
(x+y) = z;
For this statement, I get the following error with g++ compiler:
error: non-lvalue in assignment
Suppose I have a class Test and x, y, z are objects of type Test.
Suppose I have
Test Test:
perator+(const Test& ref);
Test operator+=(Test lhs, Test rhs);
Given this, the following are accepted by g++:
(x+y) = z;
(x+y) += z;
My question:
Is (x+y) an lvalue ?
I thought, x+y being a temporary object, we cannot take its address
and so not an lvalue. However the compiler accepts it on the left hand
side of the assignment operator. I am unable to understand this.
Kindly clarify
Thanks
V.Subramanian
int x;
int y;
int z;
(x+y) = z;
For this statement, I get the following error with g++ compiler:
error: non-lvalue in assignment
Suppose I have a class Test and x, y, z are objects of type Test.
Suppose I have
Test Test:
Test operator+=(Test lhs, Test rhs);
Given this, the following are accepted by g++:
(x+y) = z;
(x+y) += z;
My question:
Is (x+y) an lvalue ?
I thought, x+y being a temporary object, we cannot take its address
and so not an lvalue. However the compiler accepts it on the left hand
side of the assignment operator. I am unable to understand this.
Kindly clarify
Thanks
V.Subramanian