Some, such as pass-by-pointer, are better off when the object being passed is actually modified. They use pass-by-const-reference when the object is passed by reference to avoid copying the object, but will not change in the function.
As an illustration, perform the following functions:
int foo(int x); int foo1(int &x); int foo2(int *x);
Now in the code, I do the following:
int testInt = 0; foo(testInt);
When calling foo vs foo1, it is not obvious from the point of view of callers (or programmers reading the code) that the function can change testInt without looking at the signature of the function. Looking at foo2, the reader can easily see that the function can actually change the value of testInt because the function gets the address of the parameter. Note that this does not guarantee that the object is actually modified, but one that helps in using references or pointers. In general, if you want to follow this guide sequentially, you should always pass const links when you want to avoid copying, and pass a pointer when you want to change the object.
RC Mar 31 2018-10-10T00: 00Z
source share