Initializing a Reference

A reference cannot exist without a variable to refer to, and it cannot be manipulated as an independent entity. Therefore, you normally initialize a reference, explicitly giving it something to refer to, when you declare it.

There are some exceptions to this rule. You need not initialize a reference in the following situations:

It is declared with extern, which means it has been initialized elsewhere.

It is a member of a class, which means it is initialized in the class's constructor function (see Chapter 4).

It is declared as a parameter in a function declaration or definition, which means its value is established when the function is called.

It is declared as the return type of a function, which means its value is established when the function returns something.

As you work through the examples in this and later chapters, note that a reference is initialized every time it is used, unless it meets one of these criteria.