home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!sdd.hp.com!usc!news.cerf.net!nic.cerf.net!hlf
- From: hlf@nic.cerf.net (Howard Ferguson)
- Newsgroups: comp.lang.c++
- Subject: How to prevent local instances, but allow "new"
- Date: 5 Jan 1993 18:04:16 GMT
- Organization: CERFnet Dial n' CERF Customer Group
- Lines: 23
- Sender: hlf@cerf.net
- Message-ID: <1icij0INNdhc@news.cerf.net>
- NNTP-Posting-Host: nic.cerf.net
-
- 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.
-
- I thought that giving the class a public new operator,
- but a private constructor would work, but this prevents
- any instances of either type from being created.
-
- I suppose writing a satic member function called "createSomething"
- which would then call a private constructor via new woulod work,
- but it seems a little kludgy. I want my library users to create
- their objects using new, as our creator intended, rather
- than calling some non-standard function. Has anyone got this
- to work simply by manipulating the visibility of the
- existing functions.
-
- I am reliably informed that if I wanted the inverse (i.e allow
- automic instances but dissallow dynamic creation) then making
- new private but the constructor public would work.
-
- tanx,
- hlf
-
-