In the "C++ programming language", there is an example
void g()
{
int ii = 0;
int& rr = ii;
rr++;
int* pp = &rr;
}
The author states:
This is legal, but rr++ does not increment the reference rr, rather, ++ is applied to an int that happens to be ii.
I am quite confusing about this statement, why "rr++ does not increment the reference rr"? So rr is just used as "bridge" to increment ii?
rris not an object in its own right, but merely an alternate name for some other, pre-existing object. So operations cannot be performed onrritself, but rather the other object to which it refers. In this case,rr++;is identical in effect to whatii++;would have been.rris an alternate name for another preexisting object is IMO more confusing because it just doesn't fit how things work. A reference is not another name, but it is its own entity. For exampleint &r = *new int; delete &r;after this,rstill exists, the object it referred to doesn't exist anymore. The reference has a name, it is not a name itself.