home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12655 < prev    next >
Encoding:
Text File  |  1992-08-20  |  2.5 KB  |  51 lines

  1. Newsgroups: comp.lang.c++
  2. 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
  3. From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Return value for the constructors.
  5. Message-ID: <1992Aug20.170524.3452@sunb10.cs.uiuc.edu>
  6. Sender: news@sunb10.cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. 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>
  9. Distribution: usa
  10. Date: Thu, 20 Aug 1992 17:05:24 GMT
  11. Lines: 38
  12.  
  13. In <matt.714318343@centerline.com> matt@centerline.com (Matt Landau) writes:
  14.  
  15. >In <2273@devnull.mpd.tandem.com> rgp@mpd.tandem.com (Ramon Pantin) writes:
  16. >>>>Sure there is: Overload operator new()...
  17. >>>
  18. >>>*****>    Clever...but it's not reentrant.
  19.  
  20. >>Paul, that is a moot point given that the object might not always be
  21. >>created thru new.  All the flag setting/checking by Josh's overloaded
  22. >>new ends up being ignored for automatic objects (i.e. local variables).
  23. >>The fact that an object wants to allocate memory thru new for its internal
  24. >>use doesn't imply that the object itself will always be created thru new.
  25.  
  26. >Of course it's fairly straightforward to FORCE all objects of a given
  27. >class to be created via the class operator new (some some other delegated
  28. >creation function).  Simply design that class so that it has no public
  29. >constructors, and make the default constructor private.  The compiler
  30. >will now refuse to let either application-level code or subclasses call
  31. >any constructor for the class.  If you want subclasses to have direct
  32. >access to the constructors, make them protected instead of private.
  33.  
  34. *****>    And this is supposed to be clean and simple??  Anyway, not
  35.     allowing auto objects to too high a price to pay.
  36.  
  37. >Arrays are still a problem; if the default constructor for a class X is 
  38. >non-public, it's not legal to say "X x_array[size];" or to dynamically 
  39. >allocate an array of X with "X *xlist = new X[size];"  It's not that you
  40. >get an array whose members have not gone through X::operator new, but
  41. >rather that you can't get an array in the first place.
  42.  
  43. >Presumably this limitation would go away if X3J16 actually designed an
  44. >operator new[] and someone actually implemented it :-)
  45.  
  46. *****>    Or better, when exception-handling gets here.
  47. -- 
  48.     - Paul J. Lucas                University of Illinois    
  49.       AT&T Bell Laboratories        at Urbana-Champaign
  50.       Naperville, IL            pjl@cs.uiuc.edu
  51.