[openbeos] Re: Pointer or reference?

  • From: "Scott MacMaster" <scott@xxxxxxxxxxxxxxxxxx>
  • To: <openbeos@xxxxxxxxxxxxx>
  • Date: Mon, 29 Mar 2004 11:40:33 -0500

I don't think that passing a pointer indicates whether the information will
be modified or not.  Whether the parameter is const or not indicates that.

As for a convention for passing a reference or pointer, I feel that
references should be used whenever possible.  There are really only 2
situations where pointers must be used otherwise I feel that they should be
avoided.  One place is inside a class that manages memory.  Examples of such
classes are string and list classes.  The other place are in designs that
use polymorphism.

Unfortunately, the BeAPI adds more places where pointers must be used mainly
because some BeAPI objects delete themselves (why anyone would make objects
that behave like that is beyond me).


Later,
Scott MacMaster

----- Original Message ----- 
From: "Waldemar Kornewald" <Waldemar.Kornewald@xxxxxx>
To: "OBOS" <openbeos@xxxxxxxxxxxxx>
Sent: Friday, March 26, 2004 9:10 AM
Subject: [openbeos] Pointer or reference?


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.

Bye,
Waldemar




Other related posts: