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