home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- 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
- From: swillden@news.ccutah.edu (Shawn Willden)
- Subject: Re: question on REFERENCES
- Message-ID: <1992Nov18.003803.29938@fcom.cc.utah.edu>
- Sender: news@fcom.cc.utah.edu
- Organization: University of Utah Computer Center
- X-Newsreader: Tin 1.1 PL3
- References: <1992Nov17.141055.19557@relay.nswc.navy.mil>
- Date: Wed, 18 Nov 92 00:38:03 GMT
- Lines: 28
-
- kestes@nswc-wo.nswc.navy.mil (Kent Estes) writes:
- : Hello netters,
- :
- : I am working on a function that references objects via id. Upon finding
- : an object, it returns a reference to that object. My question is :
- : if the object is not found, what is the best way to handle this. If
- : I were returning pointers to objects, all I would have to do is
- : return NULL.
-
- So return a pointer. There is no way to return a NULL reference (which
- is good, if you have a reference you *know* that it refers to something).
-
- If there really is a good reason why you need to return a reference
- instead of a pointer you can declare a special object of the return
- type that is always to be returned in case of error and then compare
- the address of the returned object with the address of the error
- object (or overload operator== and play games with that). Usually,
- though, you're better off just returning a pointer.
-
- :
- : tnx kl.
- :
- : reply via email not encouraged.
- :
-
- --
- Shawn Willden
- swillden@icarus.weber.edu
-