The Reference Type

A reference type is an alias for an object. It is similar to a pointer, but differs in two respects. First, a reference must be initialized. It is an error not to initialize a reference and your compiler will complain if you try to create an unitialized reference. Second, a reference cannot be made to point to an object to which it was not initialized.

References can be used as l-values (an l-value is something that can appear on the left side of an assignment). This is especially handy if you want to do something like overload the assignment operator.

Reference declaration

int number = 0; //an initialized int

int &rNumber = number; //a reference to that int

How is it used?

Given the above declaration, rNumber += 10 is legal.

Passing a reference as a function argument circumvents the pass-by-value default behavior of an argument passed to a function.

...more to come...still under development

Hosted by www.Geocities.ws

1