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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!saimiri.primate.wisc.edu!sdd.hp.com!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!eff!news.byu.edu!ux1!fcom.cc.utah.edu!swillden
  3. From: swillden@news.ccutah.edu (Shawn Willden)
  4. Subject: Re: question on REFERENCES
  5. Message-ID: <1992Nov18.003803.29938@fcom.cc.utah.edu>
  6. Sender: news@fcom.cc.utah.edu
  7. Organization: University of Utah Computer Center
  8. X-Newsreader: Tin 1.1 PL3
  9. References: <1992Nov17.141055.19557@relay.nswc.navy.mil>
  10. Date: Wed, 18 Nov 92 00:38:03 GMT
  11. Lines: 28
  12.  
  13. kestes@nswc-wo.nswc.navy.mil (Kent Estes) writes:
  14. : Hello netters,  
  15. : I am working on a function that references objects via id.  Upon finding
  16. : an object, it returns a reference to that object.  My question is :
  17. : if the object is not found, what is the best way to handle this.  If 
  18. : I were returning pointers to objects, all I would have to do is
  19. : return NULL.
  20.  
  21. So return a pointer.  There is no way to return a NULL reference (which
  22. is good, if you have a reference you *know* that it refers to something).
  23.  
  24. If there really is a good reason why you need to return a reference 
  25. instead of a pointer you can declare a special object of the return
  26. type that is always to be returned in case of error and then compare
  27. the address of the returned object with the address of the error 
  28. object (or overload operator== and play games with that).  Usually,
  29. though, you're better off just returning a pointer.
  30.  
  31. : tnx kl.
  32. : reply via email not encouraged.
  33.  
  34. --
  35. Shawn Willden
  36. swillden@icarus.weber.edu
  37.