C++ reference

When you use a reference at the parameter, it gets bound to the outside variable that gets passed in. Namely, in our example, passByRef gets bound to variable. Modifications are made up the same address.

A reference can only be bound ONCE.

Thus, once it gets bound, any modification to that reference takes place outside as well.
So for any assignments inside method test, it happens to variable on the outside as well.

If you try to rebind the reference doing something like:

you’ll get an reassignment error.

	

Leave a Reply