home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16659 < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.4 KB  |  38 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!rational.com!thor!rmartin
  3. From: rmartin@thor.Rational.COM (Bob Martin)
  4. Subject: Re: question on REFERENCES
  5. Message-ID: <rmartin.722281996@thor>
  6. Sender: news@rational.com
  7. Organization: Rational
  8. References: <1992Nov17.073603.5235@murdoch.acc.Virginia.EDU> <75096@hydra.gatech.EDU> <1992Nov17.141055.19557@relay.nswc.navy.mil>
  9. Date: Fri, 20 Nov 1992 17:53:16 GMT
  10. Lines: 26
  11.  
  12. kestes@nswc-wo.nswc.navy.mil (Kent Estes) writes:
  13.  
  14. |Hello netters,  
  15.  
  16. |I am working on a function that references objects via id.  Upon finding
  17. |an object, it returns a reference to that object.  My question is :
  18. |if the object is not found, what is the best way to handle this.  If 
  19. |I were returning pointers to objects, all I would have to do is
  20. |return NULL.
  21.  
  22. My own preference is to return pointers if the functon can fail, and
  23. to return references only if the function cannot fail, or uses
  24. exceptions to report the failure.
  25.  
  26. This provides a very convenient paradigm, to wit: References never
  27. need to be checked, pointers always do.  This works equally well for
  28. function arguments where references must always be valid, but pointers
  29. may be zero.
  30.  
  31.  
  32.  
  33. --
  34. Robert Martin                        Training courses offered in:
  35. R. C. M. Consulting                       Object Oriented Analysis
  36. 2080 Cranbrook Rd.                        Object Oriented Design
  37. Green Oaks, Il 60048 (708) 918-1004       C++
  38.