Summary

In this chapter, we looked at the dark side of C++ power. I did not want to frighten you, rather to convey to you the grave responsibility that a C++ programmer has—both for program performance and for program integrity.

I drove several more nails in the coffin of passing parameters by value, and I hope you will not compromise on that in your programs. Pass parameters by reference, and use the const modifier to indicate that the parameter does not change in the function.

I also argued against returning objects from functions by value. If you have to return an object, return the reference to the object, but make sure that this reference is to an object that does not disappear immediately after the function call.

If you feel strongly that ...

Get Core C++ A Software Engineering Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.