Lecture overview -- Keyboard shortcut: 'u'  Previous page: Strings - examples -- Keyboard shortcut: 'p'  Next page: Rules for references -- 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 15 : 42
Notes about C++
Basic facilities
References

A reference in C++ is an alias

A reference is an alternative name for an object

  • The C++ Programming Language: Page 97
 

  int k = 3;
  double a = 5.0;
  double &d = a;
  void f(int &i, double &d);
  f(k,a);

C++ References.

 

  • Why references in C++?

    • An implementation of call-by-reference parameters - instead of relying on pointers passed by value

    • An optimization of large call-by-value parameters - by means of const references (meaning: a reference to a constant)

      • Name binding to temporary objects

    • Essential for parameters of copy constructors and assignment operator overloads

  • The C++ Programming Language: Argument passing. Value return. Page 145-148
 

A reference in C++ can be understood as a generalization of "call by reference parameters"