Pointer/Reference etiquette

Question is:

Should I only pass as pointer (instead of a reference) when I want it to be re-seated?

So the syntax f( myStruct* const arg ) never needs to be used because it's the same as f( myStruct& arg )?

It seems like such a limited type of case would use a re-seatable pointer argument.
Last edited on
Unless you actually want to do something other than dereference the pointer. The pointer is a complete object in its own right, and sometimes there are needs to do something for which you need a copy of the pointer to the object, not a reference to the object.
So the syntax f( myStruct* const arg ) never needs to be used because it's the same as f( myStruct& arg )?
It's not exactly the same. When passing a reference, you are forced to pass a valid object. Passing a pointer allows you to pass a null pointer, which is useful in some situations
Don't forget the (abomination of) void pointers, allowing you to throw around anything you jolly well like. References (thankfully) won't do that :)
But these are typed pointers.
The original question did not involve types; it asked if one should only pass pointers when one wants to reseat.
Topic archived. No new replies allowed.