References available upon request
Jesse Liberty · 1999
In my previous column,1 I talked at length about pointers; this month the focus is on references. A reference is an alias to an object. While it is often implemented by the compiler using pointers, that fact is only a distraction, and you should not allow it to confuse you; references and pointers are quite different. A pointer is a variable that holds the address of an object. A reference is an alias for an object. Pointers may be null references may not be null—you can't alias nothing. References must be initialized. You create a reference by writing the type of the target object, followed by the reference operator (&), followed by the name of the reference. Thus, if you already have an integer variable named someInt, you can make a reference to that variable by writing: int &someRef = someInt; This is read as "someRef is a reference to integer and someRef is initialized to refer to someInt, " or more commonly, "someRef is a reference to someInt." If you ask a reference for its address, it returns the address of its target. That is the nature of references. They are aliases for the target. This can get you in trouble. Even