Boost logo

Boost Users :

From: Nevin \ (nevin_at_[hidden])
Date: 2008-05-16 15:47:38


2008/5/16 Kevin Martin <kev82_at_[hidden]>:
> func1() may be a member function of an object which needs to keep the
> argument somewhere, that is why I prefer to pass a pointer.

If it is keeping the argument, then it cares about ownership/lifetime,
so one should pass a smart pointer to it.

> Passing a
> reference gives the implication (at least to me) that the object is
> not going to keep any link with the argument after the call returns.
> Passing a pointer makes me think - hey, what is this object doing with
> this thing?

It doesn't convey that information to other readers of your code. All
the language rules really give you is that passing by reference means
that the variable must exist, while passing by pointer means that it
could be NULL.

-- 
 Nevin ":-)" Liber <mailto:nevin_at_[hidden]> (847) 691-1404

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net