References
are a C++ feature that are like constant pointers automatically dereferenced by
the compiler.
Although
references also
exist in Pascal, the C++ version was taken from the Algol language. They are
essential in C++ to support the syntax of operator overloading (see
Chapter XX), but are also a general convenience to control the way arguments
are passed into
and out of functions.
This
chapter will first look briefly at the differences between pointers in
C and C++, then introduce references. But the bulk of the chapter will delve
into a rather confusing issue for the new C++ programmer: the copy-constructor,
a special constructor (requiring references) that makes a new object from an
existing object of the same type. The copy-constructor is used by the compiler
to pass and return objects
by
value
into
and out of functions.
Finally,
the somewhat obscure C++
pointer-to-member
feature is illuminated.