home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18964 < prev    next >
Encoding:
Internet Message Format  |  1993-01-11  |  1.9 KB

  1. Path: sparky!uunet!charon.amdahl.com!netcomsv!netcomsv!ulogic!hartman
  2. From: hartman@ulogic.UUCP (Richard M. Hartman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: why `int X: :X()' ?
  5. Message-ID: <848@ulogic.UUCP>
  6. Date: 11 Jan 93 19:36:57 GMT
  7. References: <1992Dec30.172537.12477@csi.jpl.nasa.gov> <5501@miramon.lulea.trab.se>
  8. Organization: negligable
  9. Lines: 47
  10.  
  11. In article <5501@miramon.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
  12. >Matt Wette (mwette@csi.jpl.nasa.gov) wrote:
  13. >
  14. >: Why are constructor and destructor functions usually declared to return
  15. >: ints when the usage typically warrents a `void' declaration.
  16. >
  17. >The "default int" rule does not apply to constructors and destructors.
  18. >You can't return an "int" from those functions.  You can't explicitly
  19. >mark them as procedures (void) either.
  20. >
  21. >I'd say that "default void" (as for constructors and destructors)
  22. >makes more sense than "default int".  Having no default type at all
  23. >makes the most sense, avoiding compiler and programmer confusion.
  24.  
  25. I'd say you are misleading yourself.  The best way (IMHO) to think
  26. of constructors is returning the type for which they are a constructor.
  27.  
  28. e.g. (if you could):
  29.     
  30.     classType classType::classType() {}
  31.  
  32. but this would have been very confusing.  Therefore, just
  33.  
  34.     classType::classType() {}
  35.  
  36. but if you start thinking of
  37.  
  38.     void classType::classType() {}
  39.  
  40. Then declarations such as:
  41.  
  42.     classType classInstance = classType();
  43.  
  44. won't really make sense.  Don't try to second guess the
  45. spec and put a mental "void" infront of the constructor,
  46. because it doesn't belong there any more than the "int"
  47. which would normally be implied (if the exception weren't
  48. called out) belongs there.
  49.  
  50.  
  51.  
  52.         -Richard Hartman
  53.         hartman@ulogic.COM
  54.  
  55. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  56. "There are no problems, only opportunities!"
  57. "What we have here is an insurmountable opportunity..."
  58.