Basic facilities
- slide 19 : 42
References versus Pointers
Examples that compare programming with pointers and C++ references
Two versions of swap - with references and with pointers.
Observations
The notational overhead - use of
&
and
*
- is less for use of references than for pointers
The reason is that it is not possible to manipulate the reference as such
The mental models are different
Pointers: Establish pointer to an object, follow the pointer to the object for lhs/rhs access
References: Establish an alternative name to an existing object
A reference may be implemented as a
constant pointer
that is dereferenced automatically each time it is used