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

  1. Path: sparky!uunet!gumby!wupost!cs.utexas.edu!unisql!nandraj
  2. From: nandraj@unisql.UUCP (Nandraj Arni)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Return values for constructors.
  5. Message-ID: <3474@unisql.UUCP>
  6. Date: 19 Aug 92 14:10:22 GMT
  7. Reply-To: nandraj@unisql.UUCP (Nandraj Arni)
  8. Organization: UniSQL, Inc., Austin, Texas, USA
  9. Lines: 53
  10.  
  11. n
  12. >
  13. >>   Why does C++ not let you have a return value for a constructor?
  14. >>Is there any rationale behind this?
  15. >
  16. >*****>    Because there's nothing for it to return.  A c'tor is s'posed to
  17. >    turn raw memory into an object.  Period.
  18. >
  19. >    Anyway, where would the return value _go_?
  20. >
  21. >    class Foo {
  22. >        int Foo( ... ) { ... return expr; }    // hypothetical
  23. >    };
  24. >
  25. >    Foo x(...);            // no use for a return-value here
  26. >    Foo *p = new Foo(...);        // nor here; the address is returned
  27.  
  28.  
  29.    One way would be like this:
  30.  
  31.    Foo *p;
  32.  
  33.    int return_value = new p(...); // not allowing Foo *p = new Foo(...);
  34.                   // This could be invalid assingment...
  35.  
  36.  
  37.    And for others:
  38.  
  39.    float value;        // This does not have a value, even objects
  40.                // should be like that.
  41.  
  42.  
  43.    So other way would be:
  44.  
  45.    Foo p;
  46.  
  47.    int return_value = p(...);
  48.  
  49.  
  50.  
  51.    
  52.  
  53. -- 
  54. *******************************************************************
  55. Nandraj Arni
  56.  
  57. UniSQL, Inc.                           Voice: 512 343 7372 Ext. 107
  58. 9390 Research Blvd.                              Home: 512 794 9386
  59. Kaliedo II                             FAX: 512 343 7383
  60. Austin, TX 78759
  61.  
  62. Email: unisql!nandraj@cs.utexas.edu
  63. *******************************************************************
  64.