Class 16: Function Parameters and Polymorphism

Slides

Display version (pdf).

Downloads

Homework

Reading (for next class): SICP, Section 3.2.

Exercises

  1. In class, we saw how pass by reference is very similar to pass by value/result but has slightly different semantics. Write a (small!) C++ program that demonstrates reference parameters (indicated with an ampersand like in void foo(int& x) {...}) are really passed by reference and not by value/result. That is, you should write a small program that would do a different thing in each of these two parameter passing modes.
  2. Which of the four parameter passing modes do you think is most closely represented when a function is passed a pointer? Explain your reasoning in a sentence or two.