According to Wikipedia, function calls don't copy parameters which are are references
to a const
type:
void f_slow(BigObject x);
void f_fast(const BigObject& x);
f_slow(y); // slow, copies y to parameter x
f_fast(y); // fast, gives direct read-only access to y
Why does the reference need to be const
? Wouldn't a non-const
reference accomplish the same:
void f_should_be_fast(BigObject& x);