Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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"

share|improve this answer

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.

share|improve this answer
1  
Did you mean to switch "implementation" and "semantics" as well as "value" and "reference"? Because, to me, it would have made more sense if you kept "implementation" and "semantics" as is and only switched "value" and "reference". Also what do you mean by "const reference paramater (doesn't exist)"? Const references do exist. –  sepp2k Oct 27 '12 at 9:53
2  
What do you mean, doesn't exist? const T& absolutely does exist in C++. –  DeadMG Oct 27 '12 at 19:30
1  
My mistake on the const reference. –  jmoreno Oct 27 '12 at 20:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.