A reference is
always another name for some object.
The issue is
how the reference works. The standard makes room for different considerations when implementing it.
For example, in the following code, it is very easy for the compiler to optimize the existence of
y away. You could do the same by just replacing every instance of "y" with "x" and deleting line 2:
1 2
|
int x = 12;
int& y = x;
|
However, in the following code, the reference may not always be an alias to the
same object:
1 2 3 4
|
void quuxify( int& n )
{
n = n * 7;
}
|
because it may be used like this:
1 2 3
|
int a=2, b=3;
quuxify( a );
quuxify( b );
|
The compiler has a couple of options. It could
inline the function, and make it a true alias, which gets optimized away (the same as if you just wrote
a = a * 7;
and
b = b * 7;
. Or it could implement it as a pointer underneath.
From your point of view, however, it is still an alias for some other object.
Hope this helps.