Lecture overview -- Keyboard shortcut: 'u'  Previous page: References versus Pointers -- Keyboard shortcut: 'p'  Next page: Value return -- 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 20 : 42
Notes about C++
Basic facilities
Parameter passing in C++

It is possible to pass parameters by value, by a pointer, and via a C++ reference

  • Call by value

    • Copy actual parameters and bind to formal parameters

      • Formal parameters are initialized - not assigned.

      • For user-defined types: It is possible to control what copying means - via a copy constructor

      • In the copy constructor itself, call-by-C++-reference parameter passing is crucial.

    • In the special case: Passing pointers by value (C-style call-by-reference)

  • Call by (C++) reference

    • The formal parameter becomes an alias of the actual parameter

    • Call by const reference is an attractive alternative to call by value parameters

      • No overhead due to copying

      • No risk of modifying the actual parameter via the formal parameter