3 ms·
> References can be copied > But it doesn’t do the same thing as assigning to them I think, that's not a good mental model for references. A reference is an op
by yokaze 6y ago
> References can be copied
> But it doesn’t do the same thing as assigning to them
I think, that's not a good mental model for references.
A reference is an opaque data type.
The initial assignment is "taking a reference" and all later operations work the same, as you would refer to the referenced object itself.
So
int& r2 = r1; // r2 now points to i, like r1
I would rather say
int& r2 = r1; // r2 now references i, like r1
Because it isn't a pointer. It may be implemented as one (e.g. when passing arguments to functions), but in this case, I don't think, even that will happen. You just have another name for the same object.