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?
If I need to pass an array of objects, I need to pass by pointer. Arrays aren't always stored in std::vector<>
.
Other than that, pass by pointer allows NULL and pass by reference doesn't, so I use that distinction as a contract much like NULL
vs. NOT NULL
columns in SQL, and loosely like "function returning bool
: true
= succeeded and false
= failed, vs. function returning int
: return value is a result code where 0
= success and others are failures".