home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- 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
- From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
- Subject: Re: Return value for the constructors.
- Message-ID: <1992Aug19.163545.25066@sunb10.cs.uiuc.edu>
- Sender: news@sunb10.cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <3462@unisql.UUCP> <1992Aug18.210426.19494@sunb10.cs.uiuc.edu> <H575V1E@netmbx.netmbx.de>
- Distribution: usa
- Date: Wed, 19 Aug 1992 16:35:45 GMT
- Lines: 32
-
- In <H575V1E@netmbx.netmbx.de> jrobie@netmbx.netmbx.de (Jonathan Robie) writes:
-
- >pjl@sparc6.cs.uiuc.edu (Paul Lucas) writes:
-
- >>In <3462@unisql.UUCP> nandraj@unisql.UUCP (Nandraj Arni) writes:
-
- >>> Why does C++ not let you have a return value for a constructor?
- >>>Is there any rationale behind this?
-
- >>*****> Because there's nothing for it to return. A c'tor is s'posed to
- >> turn raw memory into an object. Period.
-
- >But note this example from the ARM, page 62:
-
- > complex* p = new complex(i++);
- > if (p == 0) // allocation failed!
-
- *****> No; the allocator new() is returning zero, not the constructor.
- Also, if the ctor further allocates it's own stuff, there is
- currently no clean way of returning that fact to the caller--
- new() will return success, i.e., non-zero.
-
- >On page 61 he also states that initialization will only be done if the
- >return from the new is nonzero.
-
- >So I think that it is safe to check the pointer to see if it is zero.
-
- *****> This has nothing to do with the original question.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-