In chapter 13, when talking about pointers, there is a paragraph:
Sometimes, however, you would like to have the semantics of pass by
reference—that is, that the passed object should not be altered—with
the implementation of pass by value—that is, passing the actual object
rather than a copy.
It seems like the author made a mistake and mixed the two up. Is this true, or am I not understanding what he’s saying correctly?
0
You’re right and this is already in the errata page of the book.
Reference Should Be Value On page 333, Change: “Sometimes, however,
you would like to have the semantics of a pass by reference” To
“Sometimes, however, you would like to have the semantics of a pass by
value”Value Should Be Reference On page 333, Change: “with the
implementation of a pass by value” To:”with the implementation of a
pass by reference”
Yes, it does seem to be mixed up. Switch it and add a bit more, and it makes sense.
Sometimes you would like to have the implementation of pass by value — that is the passed object is a copy and changes do not effect the original — with the semanics of pass by reference — that is the object itself is not passed.
This would be something like a const reference parameter. This would allow you to have a large, mutable, structure, that was, within the context of a particular function, immutable.
3