home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12567 < prev    next >
Encoding:
Text File  |  1992-08-19  |  1.7 KB  |  45 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!darwin.sura.net!wupost!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc10.cs.uiuc.edu!pjl
  3. From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Return value for the constructors.
  5. Message-ID: <1992Aug19.163545.25066@sunb10.cs.uiuc.edu>
  6. Sender: news@sunb10.cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <3462@unisql.UUCP> <1992Aug18.210426.19494@sunb10.cs.uiuc.edu> <H575V1E@netmbx.netmbx.de>
  9. Distribution: usa
  10. Date: Wed, 19 Aug 1992 16:35:45 GMT
  11. Lines: 32
  12.  
  13. In <H575V1E@netmbx.netmbx.de> jrobie@netmbx.netmbx.de (Jonathan Robie) writes:
  14.  
  15. >pjl@sparc6.cs.uiuc.edu (Paul Lucas) writes:
  16.  
  17. >>In <3462@unisql.UUCP> nandraj@unisql.UUCP (Nandraj Arni) writes:
  18.  
  19. >>>   Why does C++ not let you have a return value for a constructor?
  20. >>>Is there any rationale behind this?
  21.  
  22. >>*****>    Because there's nothing for it to return.  A c'tor is s'posed to
  23. >>    turn raw memory into an object.  Period.
  24.  
  25. >But note this example from the ARM, page 62:
  26.  
  27. >    complex* p = new complex(i++);
  28. >    if (p == 0)  // allocation failed!
  29.  
  30. *****>    No; the allocator new() is returning zero, not the constructor.
  31.     Also, if the ctor further allocates it's own stuff, there is 
  32.     currently no clean way of returning that fact to the caller--
  33.     new() will return success, i.e., non-zero.
  34.  
  35. >On page 61 he also states that initialization will only be done if the
  36. >return from the new is nonzero.
  37.  
  38. >So I think that it is safe to check the pointer to see if it is zero.
  39.  
  40. *****>    This has nothing to do with the original question.
  41. -- 
  42.     - Paul J. Lucas                University of Illinois    
  43.       AT&T Bell Laboratories        at Urbana-Champaign
  44.       Naperville, IL            pjl@cs.uiuc.edu
  45.