[openbeos] Re: Pointer or reference?

  • From: Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Sat, 27 Mar 2004 18:30:15 +0100

On 2004-03-27 at 18:01:11 [+0100], Michael Phipps wrote:
> I will speak only of my personal preference. :-)
> 
> I vastly prefer references.
> I use pointers when:
> 1) I need nullability (or anytime null is an option)
> 2) When I am using the pointer to become part of something else. Example:
> foo::initialize(int *c) {
>     intPtr=c;
> }
> 
> On 2004-03-26 at 09:10:06 [-0500], Waldemar Kornewald wrote:
> > Hi,
> > this is a code-style question:
> > When should I use a pointer as a parameter and when should I use a
> reference?
> > Is the general convention that a pointer indicates that the passed
> > information will be modified? But the BMessage in MessageReceived() is a
> > pointer although it is not intended to be modified by the receiver.

In the BeOS API references are used rather sparingly in wide parts 
(basically only for copy constructors and comparison/assignment operators). 
Exceptions are the media kit and the net kit, both feeling a bit un-Be-ish 
anyway, IMHO.

So, I would say, for public APIs (or those that may become public in the 
future), references should be avoided.

CU, Ingo

Other related posts: