11: References & the Copy-Constructor
References are like constant
pointers that are 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 12),
but they 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.
|