More on Passing Objects by Value

Earlier, in Chapter 7, "Programming with C++ Functions," I argued against passing objects to functions as value parameters or as pointer parameters and promoted passing parameters by reference instead.

I explained that pass by reference is almost as simple as pass by value, but it is faster—for input parameters that are not modified by the function. Pass by reference is as fast as pass by pointer, but its syntax is much simpler—for output parameters that are modified by the function in the course of its execution.

I also noticed that the syntax for pass by reference is exactly the same for both input and output function parameters. This is why I suggested that you use the const modifier for input parameters, ...

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.