I usually use pass by reference in the following situations:
1) objetc is larger than the pointer: in this case, if I do not want to change objetc, use the const link:
Reference object; foo(object);
with foo declared as:
void foo(const Reference & object);
2) For the code, try to avoid such ticks:
int f1 = xxx; int f2 = yyy; int f3 = zzz; .... foo(f1, f2, ............)
using struct:
struct X { int f1; int f2; int f3; .... }; X x; x.f1 = xxx; ..... foo(X);
with foo defined as:
foo(const X & x);
3) to speed up the fill: remember that calling functions must put parameters on the stack 4) You need to change the parameters inside the function.
Reference object; foo(object);
with foo declared as:
void foo(Reference & object);
Tio pepe
source share