home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!centerline!matt
- From: matt@centerline.com (Matt Landau)
- Subject: Re: Return value for the constructors.
- Message-ID: <matt.714318343@centerline.com>
- Sender: news@centerline.com
- Nntp-Posting-Host: rapier
- Organization: CenterLine Software, Inc.
- References: <1992Aug19.163545.25066@sunb10.cs.uiuc.edu> <1992Aug19.175852.38459@watson.ibm.com> <1992Aug19.231926.28218@sunb10.cs.uiuc.edu> <2273@devnull.mpd.tandem.com>
- Distribution: usa
- Date: Thu, 20 Aug 1992 13:45:43 GMT
- Lines: 27
-
- In <2273@devnull.mpd.tandem.com> rgp@mpd.tandem.com (Ramon Pantin) writes:
- >>>Sure there is: Overload operator new()...
- >>
- >>*****> Clever...but it's not reentrant.
-
- >Paul, that is a moot point given that the object might not always be
- >created thru new. All the flag setting/checking by Josh's overloaded
- >new ends up being ignored for automatic objects (i.e. local variables).
- >The fact that an object wants to allocate memory thru new for its internal
- >use doesn't imply that the object itself will always be created thru new.
-
- Of course it's fairly straightforward to FORCE all objects of a given
- class to be created via the class operator new (some some other delegated
- creation function). Simply design that class so that it has no public
- constructors, and make the default constructor private. The compiler
- will now refuse to let either application-level code or subclasses call
- any constructor for the class. If you want subclasses to have direct
- access to the constructors, make them protected instead of private.
-
- Arrays are still a problem; if the default constructor for a class X is
- non-public, it's not legal to say "X x_array[size];" or to dynamically
- allocate an array of X with "X *xlist = new X[size];" It's not that you
- get an array whose members have not gone through X::operator new, but
- rather that you can't get an array in the first place.
-
- Presumably this limitation would go away if X3J16 actually designed an
- operator new[] and someone actually implemented it :-)
-