< Previous | Contents | Next >
Back in main(), I create inventory and then call display() with the following line, which passes the vector as a constant reference.
display(inventory);
198 Chapter 6 n References: Tic-Tac-Toe
This results in an efficient and safe function call. It’s efficient because only a reference is passed; the vector is not copied. It’s safe because the reference to the vector is a constant reference; inventory can’t be changed by display().
Tra p
You can’t modify a parameter marked as a constant reference. If you try, you’ll generate a compile error.
Next, display() lists the elements in the vector using a constant reference to
inventory. Then control returns to main() and the program ends.