I can imagine one case, in which the input parameter could be NULL so that pass-by-pointer is preferred but not pass-by-reference?
Can anybody add more cases?
Google seems to have a strong opinion on this, and I tend to agree:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Reference_Arguments
You have many situations in real world programming wherein a parameter does not exist or is invalid and this can depend on runtime semantics of the code. In such situations you can use NULL (0) to signal this state. Apart from this,
Although if enough time is spent designing the code properly, these situations can be avoided; in practice it is not possible everytime.
In addition to some other answers about ownership semantics (especially factory functions).
While not a technical reason, a common style guide requirement is that any parameters that may be modified should be passed by pointer. This makes it obvious at the callsite that the object may be modified.
void Operate(const int &input_arg, int *output_arg) {
*output_arg = input_arg + 1;
}
int main() {
int input_arg = 5;
int output_arg;
Foo(input_arg, &output_arg); // Passing address, will be modified!
}
This isn't specifically argument passing, but it does affect argument passing.
You can have a container/aggregate of pointers, but not of references. Although references are polymorphic, only pointers support the "update" operation which is essential to container use (especially since you can't yet initialize references en masse, not sure if C++0x aggregate initializers will change that).
So if you have a container full of pointers, you will usually end up managing it with functions that accept pointers rather than references.
When you need to manipulate (e.g. resize, reassign, etc.) the address being pointed to by the pointer inside the function, then you need a pointer.
For example:
void f( int* p )
{
// ..
delete []p;
p = new int[ size ];
//...
}
Unlike references, values of pointers can be changed and manipulated.
A function could, conceivably, be written to do something with the memory, such as reallocating it to make it larger (returning the new pointer).