Glossary: Reference

A reference is simply an alternative identifier for a variable or object. Its rather like the FORTRAN EQUIVALENCE, except that it can be defined at execution time (something some of us have wished FORTRAN could do as well!). Clearly, as this is an execution time feature, a pointer has to be involved. When a reference identifier is declared it must be initialised with the address of the variable it is a reference to, for example:-
Int_t  &my_int = your_int;
This makes my_int a reference to your_int. From now on the two identifiers are equivalent. Behinds the scenes, the compiler knows that it only has a pointer and has to do some dereferencing, but this is all automatic - it better to forget about this trickery and just think of it as an alternative name. References cannot do anything that pointers cannot do, however, they can make some code a lot clearer by removing lots of explicit dereferences.

Once defined, a reference cannot be reassigned a new value.

See OO Concepts: Pointers & References
Go Back to the The Glossary Top Page

If you have any comments about this page please send them to Nick West