home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13356 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.6 KB  |  40 lines

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