home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!netcomsv!netcomsv!ulogic!hartman
- From: hartman@ulogic.UUCP (Richard M. Hartman)
- Newsgroups: comp.lang.c++
- Subject: Re: why `int X: :X()' ?
- Message-ID: <848@ulogic.UUCP>
- Date: 11 Jan 93 19:36:57 GMT
- References: <1992Dec30.172537.12477@csi.jpl.nasa.gov> <5501@miramon.lulea.trab.se>
- Organization: negligable
- Lines: 47
-
- In article <5501@miramon.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
- >Matt Wette (mwette@csi.jpl.nasa.gov) wrote:
- >
- >: Why are constructor and destructor functions usually declared to return
- >: ints when the usage typically warrents a `void' declaration.
- >
- >The "default int" rule does not apply to constructors and destructors.
- >You can't return an "int" from those functions. You can't explicitly
- >mark them as procedures (void) either.
- >
- >I'd say that "default void" (as for constructors and destructors)
- >makes more sense than "default int". Having no default type at all
- >makes the most sense, avoiding compiler and programmer confusion.
-
- I'd say you are misleading yourself. The best way (IMHO) to think
- of constructors is returning the type for which they are a constructor.
-
- e.g. (if you could):
-
- classType classType::classType() {}
-
- but this would have been very confusing. Therefore, just
-
- classType::classType() {}
-
- but if you start thinking of
-
- void classType::classType() {}
-
- Then declarations such as:
-
- classType classInstance = classType();
-
- won't really make sense. Don't try to second guess the
- spec and put a mental "void" infront of the constructor,
- because it doesn't belong there any more than the "int"
- which would normally be implied (if the exception weren't
- called out) belongs there.
-
-
-
- -Richard Hartman
- hartman@ulogic.COM
-
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- "There are no problems, only opportunities!"
- "What we have here is an insurmountable opportunity..."
-