home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18794 < prev    next >
Encoding:
Text File  |  1993-01-07  |  1.6 KB  |  37 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!ascent!ascent!eb
  3. From: eb@ascent.com (Ed Barton)
  4. Subject: Re: How to prevent local instances, but allow "new"
  5. In-reply-to: bruceb@roadrunner.denver.sgi.com's message of Tue, 5 Jan 1993 19:42:23 GMT
  6. Message-ID: <EB.93Jan7092124@MountRushmore.ascent.com>
  7. Date: 7 Jan 93 09:21:24
  8. References: <1icij0INNdhc@news.cerf.net> <1993Jan5.194223.19400@odin.corp.sgi.com>
  9. Organization: Ascent Technology, Inc., Cambridge Massachusetts
  10. Lines: 25
  11.  
  12. In article <1993Jan5.194223.19400@odin.corp.sgi.com> bruceb@roadrunner.denver.sgi.com (Bruce Bailey) writes:
  13.  
  14.    In article <1icij0INNdhc@news.cerf.net>, hlf@nic.cerf.net (Howard Ferguson)
  15.    writes:
  16.    |> I wish to define a class in a library which the library user
  17.    |> can create by dynamic allocation via the new operator, but
  18.    |> I want to prevent him from creating automic instances.
  19.  
  20.    Make the destructor private.
  21.  
  22. In at least one compiler implementation, making the destructor private
  23. will also prevent ever having any subclasses of the class.  In many
  24. cases where you are making the constructor or destructor private, you
  25. actually want to make it protected so that subclasses will be
  26. possible.
  27.  
  28. By the way, note that when you want to prevent automatic allocation on
  29. the stack so that you can do "delete" later, you also want to prevent
  30. containment in other objects, whether or not those other objects are
  31. allocated on the heap.  Most solutions that prevent automatic
  32. allocation also prevent containment, but I have found that many people
  33. forget about containment when they are thinking about this issue, and
  34. remember only stack variables and "new" allocations.
  35.  
  36.  
  37.