This is a call by value, where the value of the aFoo pointer aFoo copied to the function parameter f .
A call by reference is a call where the parameter is a link, and side effects on the argument (and not on the objects pointed to by this argument) that occur inside the function are visible to the caller when the function returns,
So, for example, this is a function that takes a parameter by reference:
void bar(foo*& f)
While this is a function that takes a parameter by value:
void bar(foo* f)
You are probably puzzled by the fact that with foo you can reference and write:
void bar(foo& f) { f.insert(); }
has almost the same effect as passing a pointer to the same foo object by value and record:
void bar(foo* f) {
However, two things are conceptually different. Although the value / state of the object that you passed in the first case may differ when the function returns from the value / state that it had before the function call, in the second case, the pointer value you specified will be the same as before how you called bar() - while the object pointed to may undergo some state change.
Also note that the pointer may be null, and the link is always bound to an object.
source share