Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is this an error in a C++ textbook?

31 views
Skip to first unread message

Paul

unread,
Jun 11, 2015, 1:11:31 PM6/11/15
to
The below appears (to me) to contain an error. Please could someone confirm if there's an error? Otherwise, I need to review my understanding of some basics. Thank you. I would have thought that &x denotes the address of a variable and is therefore not an lvalue. This is not given as an error in the online errata list.

Thanks again for your help.

BEGIN QUOTE

vector<string> arr( 3 );
const int x = 2;
int y;

...

int z = x + y;
string str = "foo";
vector<string> *ptr = &arr;

With these declarations, arr, str, arr[x], &x, y, z, ptr, *ptr, (*ptr)[x] are all lvalues.
END QUOTE

Victor Bazarov

unread,
Jun 11, 2015, 1:28:39 PM6/11/15
to
Your understanding is correct. '&x' is not an lvalue. It's an
expression that yields an rvalue (or rather a prvalue in modern C++ terms).

V
--
I do not respond to top-posted replies, please don't ask
0 new messages