home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gumby!wupost!cs.utexas.edu!unisql!nandraj
- From: nandraj@unisql.UUCP (Nandraj Arni)
- Newsgroups: comp.lang.c++
- Subject: Re: Return values for constructors.
- Message-ID: <3474@unisql.UUCP>
- Date: 19 Aug 92 14:10:22 GMT
- Reply-To: nandraj@unisql.UUCP (Nandraj Arni)
- Organization: UniSQL, Inc., Austin, Texas, USA
- Lines: 53
-
- n
- >
- >> 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.
- >
- > Anyway, where would the return value _go_?
- >
- > class Foo {
- > int Foo( ... ) { ... return expr; } // hypothetical
- > };
- >
- > Foo x(...); // no use for a return-value here
- > Foo *p = new Foo(...); // nor here; the address is returned
-
-
- One way would be like this:
-
- Foo *p;
-
- int return_value = new p(...); // not allowing Foo *p = new Foo(...);
- // This could be invalid assingment...
-
-
- And for others:
-
- float value; // This does not have a value, even objects
- // should be like that.
-
-
- So other way would be:
-
- Foo p;
-
- int return_value = p(...);
-
-
-
-
-
- --
- *******************************************************************
- Nandraj Arni
-
- UniSQL, Inc. Voice: 512 343 7372 Ext. 107
- 9390 Research Blvd. Home: 512 794 9386
- Kaliedo II FAX: 512 343 7383
- Austin, TX 78759
-
- Email: unisql!nandraj@cs.utexas.edu
- *******************************************************************
-