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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.