Connecting Tech Pros Worldwide Help | Site Map

Reference are always lvalue?

Familiar Sight
 
Join Date: Dec 2007
Posts: 200
#1: Dec 21 '07
Hello everyone,


Is the conclusion correct? Both const reference and non-const reference are lvalue?

I think it is true and I can not find a sample which does not follow it.


thanks in advance,
George
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#2: Dec 21 '07

re: Reference are always lvalue?


An lvalue means you can use the object on the left of an assignment operator.

A const reference refers to an object that can't be changed.

Therefore, a const reference can't be used as an lvalue.

That's not to say that the const reference can't be use on the left of any operator, just those that would change the object.
Familiar Sight
 
Join Date: Dec 2007
Posts: 200
#3: Dec 22 '07

re: Reference are always lvalue?


Sorry weaknessforcats,


I do not agree that lvalue is something that could be on the left side of an assignment operator, but something adressable.

Quote:

Originally Posted by weaknessforcats

An lvalue means you can use the object on the left of an assignment operator.


regards,
George
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#4: Dec 22 '07

re: Reference are always lvalue?


Quote:

Originally Posted by George2

I do not agree that lvalue is something that could be on the left side of an assignment operator, but something adressable.

Read The ANS-C Progrmaming Language by Kernighan & Ritchie page 197 Section A5.
Familiar Sight
 
Join Date: Dec 2007
Posts: 200
#5: Dec 24 '07

re: Reference are always lvalue?


Sorry weaknessforcats, I do not have that book at hand. Do you know where can I find related statements you quoted from the book from internet? :-)

If can not find, it is appreciated if you could post here if the statements are not too long.

BTW: seems you are talking about lvalue and rvalue in the context of C, but I am talking about lvalue and rvalue in the context of C++.

Quote:

Originally Posted by weaknessforcats

Read The ANS-C Progrmaming Language by Kernighan & Ritchie page 197 Section A5.


regards,
George
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#6: Dec 24 '07

re: Reference are always lvalue?


Quote:

Originally Posted by George2

BTW: seems you are talking about lvalue and rvalue in the context of C, but I am talking about lvalue and rvalue in the context of C++.

Same meaning in both languages.

Surely you have The C++ Programming Language by Bjarne Stroustrup 3rd Edition?? Look at section 4.9.6.

This is less authoritative: http://www.cs.ucsc.edu/~pohl/code/lvalue.htm.
Familiar Sight
 
Join Date: Dec 2007
Posts: 200
#7: Dec 25 '07

re: Reference are always lvalue?


Thanks weaknessforcats,


Let us come back to the conclusion. You think,

1. const reference is rvalue;
2. non-const reference is lvalue?

Right?

Quote:

Originally Posted by weaknessforcats

Same meaning in both languages.

Surely you have The C++ Programming Language by Bjarne Stroustrup 3rd Edition?? Look at section 4.9.6.

This is less authoritative: http://www.cs.ucsc.edu/~pohl/code/lvalue.htm.


regards,
George
Reply