Argument-passing guidelines
Your normal habit when passing an
argument to a function should be to pass by const reference. Although at
first this may seem like only an efficiency
concern (and you normally
don’t want to concern yourself with efficiency tuning while you’re
designing and assembling your program), there’s more at stake: as
you’ll see in the remainder of the chapter, a copy-constructor is required
to pass an object by value, and this isn’t always
available.
The efficiency savings can be substantial
for such a simple habit: to pass an argument by value requires a constructor and
destructor call, but if you’re not going to modify the argument then
passing by const reference only needs an address pushed on the
stack.
In fact, virtually the only time passing
an address isn’t preferable is when you’re going to do such
damage to an object that passing by value is the only safe approach (rather than
modifying the outside object, something the caller doesn’t usually
expect). This is the subject of the next
section.