P
pauldepstein
Take the code:
int ival = 1024;
int &refVal = ival;
My text says "a reference is just another name for an object ... we can
access refVal through ival ..."
I understand this way of using references.
However, it does seem to me that this is not the only way references
are used.
For example:
void swap (int &v1, int &v2)
{
int tmp = v2;
v2 = v1;
v1 = tmp;
}
I don't think v2 = v1 means "v2 refers to v1". I think v2 = v1 means:
Change the integer v2 refers to by assigning it to the same value that
v1 refers to. In other words the meaning of v2 = v1 is identical to
what it would mean if the signature was (int, int) instead of (int&,
int&).
How can I tell when a reference is acting as an alias and when it
isn't?
Paul Epstein
int ival = 1024;
int &refVal = ival;
My text says "a reference is just another name for an object ... we can
access refVal through ival ..."
I understand this way of using references.
However, it does seem to me that this is not the only way references
are used.
For example:
void swap (int &v1, int &v2)
{
int tmp = v2;
v2 = v1;
v1 = tmp;
}
I don't think v2 = v1 means "v2 refers to v1". I think v2 = v1 means:
Change the integer v2 refers to by assigning it to the same value that
v1 refers to. In other words the meaning of v2 = v1 is identical to
what it would mean if the signature was (int, int) instead of (int&,
int&).
How can I tell when a reference is acting as an alias and when it
isn't?
Paul Epstein