home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12582 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  1.7 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!swrinde!zaphod.mps.ohio-state.edu!malgudi.oar.net!news.ans.net!newsgate.watson.ibm.com!yktnews!admin!!mittle
  2. From: mittle@watson.ibm.com (Josh Mittleman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Return value for the constructors.
  5. Message-ID: <1992Aug19.175852.38459@watson.ibm.com>
  6. Date: 19 Aug 92 17:58:52 GMT
  7. References: <3462@unisql.UUCP> <1992Aug18.210426.19494@sunb10.cs.uiuc.edu> <H575V1E@netmbx.netmbx.de> <1992Aug19.163545.25066@sunb10.cs.uiuc.edu>
  8. Sender: news@watson.ibm.com (NNTP News Poster)
  9. Distribution: usa
  10. Organization: IBM T.J. Watson Research Center
  11. Lines: 18
  12. Disclaimer: This posting represents the poster's views, not necessarily those of IBM
  13. Nntp-Posting-Host: siena.watson.ibm.com
  14.  
  15. pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
  16.  
  17. *****>    No; the allocator new() is returning zero, not the constructor.
  18. >     Also, if the ctor further allocates it's own stuff, there is 
  19. >     currently no clean way of returning that fact to the caller--
  20. >     new() will return success, i.e., non-zero.
  21.  
  22. Sure there is: Overload operator new().  For example, give your class a
  23. static status flag.  operator new() sets it to 1, then calls ::new() to
  24. allocate the object.  Your constructors make whatever internal checks they
  25. need, and set status to 0 if there is a problem.  Then, operator new()
  26. returns a pointer to the new object or 0, depending on the success of the
  27. process.  From the users point-of-view, it simply looks like a normal call
  28. to new().
  29.  
  30. ===========================================================================
  31. Josh Mittleman (mittle@watson.ibm.com)
  32. J2-C28 T.J. Watson Research Center, PO Box 704, Yorktown Heights, NY  10598
  33.