When passing by value:
void func(Object o);
and then calling
func(a);
you will construct an Object
on the stack, and within the implementation of func
it will be referenced by o
. This might still be a shallow copy (the internals of a
and o
might point to the same data), so a
might be changed. However if o
is a deep copy of a
, then a
will not change.
When passing by reference:
void func2(Object& o);
and then calling
func2(a);
you will only be giving a new way to reference a
. "a
" and "o
" are two names for the same object. Changing o
inside func2
will make those changes visible to the caller, who knows the object by the name "a
".