home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!ux1.cso.uiuc.edu!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: <1992Aug20.170524.3452@sunb10.cs.uiuc.edu>
- Sender: news@sunb10.cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- 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> <matt.714318343@centerline.com>
- Distribution: usa
- Date: Thu, 20 Aug 1992 17:05:24 GMT
- Lines: 38
-
- In <matt.714318343@centerline.com> matt@centerline.com (Matt Landau) writes:
-
- >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.
-
- *****> And this is supposed to be clean and simple?? Anyway, not
- allowing auto objects to too high a price to pay.
-
- >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 :-)
-
- *****> Or better, when exception-handling gets here.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-