[openbeos] Re: Pointer or reference?

  • From: "Waldemar Kornewald" <Waldemar.Kornewald@xxxxxx>
  • To: <openbeos@xxxxxxxxxxxxx>
  • Date: Sat, 27 Mar 2004 19:32:32 +0100

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

References have the advantage that the function/method already says it does not 
accept NULL pointers. The data must always be defined.
Additionally, when passing a BString object it is much better to pass the 
reference because you cannot forget the &-sign and the code looks nicer:

BString string;
...
control->SetLabel(string);
versus
control->SetLabel(&string);

I really prefer the reference version. It could also state that the SetLabel() 
method does not have side-effect (i.e.: it does not modify string) which could 
be useful sometimes.

Bye,
Waldemar

Other related posts: