
me22 wrote:
On 2/9/06, Johan Johansson <johanj@ipunplugged.com> wrote:
while a pointer means that the method will be taking ownership of that pointer.
Well, it's a possibility, but again not necessarily global law I think.
Well, it's obviously not a "global law".
But what does pass-by-pointer give over pass-by-reference? There's the possibility of null, but I'd rather do optional arguments with overloaded functions or, for complicated ones, with Boost.Parameter. The only other difference is in ownership/lifetime management ( though I'd rather make that more explicit with an std::auto_ptr or other smart pointer anyways ). I basically don't see any other reason to pass by pointer except for lifetime, which is irrelevant when it's being used as an output parameter since there's no resource ownership transfer.
I'm not arguing that pass-by-pointer is preferable. I'm actually arguing the opposite. I'm just saying that just as pass-by-pointer doesn't signal "the argument may change" I'm not convinced it signals "I'll delete the argument". As for the smart pointer option, I actually wrote a response to that effect but I was kind of expecting to get slapped around with a "but I don't want to use smart pointers" and deleted it... j