Lecture overview -- Keyboard shortcut: 'u'  Previous page: Constant References -- Keyboard shortcut: 'p'  Next page: Parameter passing in C++ -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 2 - Page 19 : 42
Notes about C++
Basic facilities
References versus Pointers

Examples that compare programming with pointers and C++ references

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/references/swap.ccTwo 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