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

  1. Path: sparky!uunet!ogicse!uwm.edu!ux1.cso.uiuc.edu!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc10.cs.uiuc.edu!pjl
  2. From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Return value for the constructors.
  5. Message-ID: <1992Aug19.231926.28218@sunb10.cs.uiuc.edu>
  6. Date: 19 Aug 92 23:19:26 GMT
  7. Article-I.D.: sunb10.1992Aug19.231926.28218
  8. References: <3462@unisql.UUCP> <1992Aug18.210426.19494@sunb10.cs.uiuc.edu> <H575V1E@netmbx.netmbx.de> <1992Aug19.163545.25066@sunb10.cs.uiuc.edu> <1992Aug19.175852.38459@watson.ibm.com>
  9. Sender: news@sunb10.cs.uiuc.edu
  10. Distribution: usa
  11. Organization: University of Illinois at Urbana-Champaign
  12. Lines: 22
  13.  
  14. In <1992Aug19.175852.38459@watson.ibm.com> mittle@watson.ibm.com (Josh Mittleman) writes:
  15.  
  16. >pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
  17.  
  18. >*****>    No; the allocator new() is returning zero, not the constructor.
  19. >>     Also, if the ctor further allocates it's own stuff, there is 
  20. >>     currently no clean way of returning that fact to the caller--
  21. >>     new() will return success, i.e., non-zero.
  22.  
  23. >Sure there is: Overload operator new().  For example, give your class a
  24. >static status flag.  operator new() sets it to 1, then calls ::new() to
  25. >allocate the object.  Your constructors make whatever internal checks they
  26. >need, and set status to 0 if there is a problem.  Then, operator new()
  27. >returns a pointer to the new object or 0, depending on the success of the
  28. >process.  From the users point-of-view, it simply looks like a normal call
  29. >to new().
  30.  
  31. *****>    Clever...but it's not reentrant.
  32. -- 
  33.     - Paul J. Lucas                University of Illinois    
  34.       AT&T Bell Laboratories        at Urbana-Champaign
  35.       Naperville, IL            pjl@cs.uiuc.edu
  36.