home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!mcsun!Germany.EU.net!math.fu-berlin.de!news.uni-stuttgart.de!news
- From: KOCHER@141.58.123.1 (HARTMUT KOCHER)
- Subject: Pointer or Reference Arguments
- Message-ID: <1992Sep7.075249.22855@news.uni-stuttgart.de>
- Sender: news@news.uni-stuttgart.de (USENET News System)
- Organization: University of Stuttgart, IND
- Date: Mon, 7 Sep 1992 07:52:49 GMT
- X-News-Reader: VMS NEWS 1.20
- Lines: 28
-
- I am currently trying to find a consistent style in
- using pointer and references as function arguments.
- Currently, I am thinking about two different styles that
- I want to explain in the following paragraphs:
-
- 1) Reference arguments are used only when aliasing
- occurs and the parameter is used only during the
- lifetime of the function. Pointers are used whenever the
- function might keep a copy of the pointer for later use,
- e.g., store it in a private list.
-
- 2) Reference arguments are used whenever you must supply
- a valid object to the function. Pointers are used when 0
- might be a valid parameter as well.
-
- The first approach gives the user of a function a hint
- whether a private copy of an object may be retained by a
- function. The second approach makes implementation
- easier because you don╘t have to check for 0-pointers so
- often. The user also sees if he must supply an object or
- if 0 is allowed as a valid parameter. I think both
- versions have something going for them and I am
- interested in hearing from you which one you think is
- best. (Or if you have yet another solution to this.)
- Any opinions?
-
- Hartmut Kocher
- Kocher@nvdv.e-technik.uni-stuttgart.dbp.de
-