home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18710 < prev    next >
Encoding:
Internet Message Format  |  1993-01-05  |  1.3 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!sdd.hp.com!usc!news.cerf.net!nic.cerf.net!hlf
  2. From: hlf@nic.cerf.net (Howard Ferguson)
  3. Newsgroups: comp.lang.c++
  4. Subject: How to prevent local instances, but allow "new"
  5. Date: 5 Jan 1993 18:04:16 GMT
  6. Organization: CERFnet Dial n' CERF Customer Group
  7. Lines: 23
  8. Sender: hlf@cerf.net
  9. Message-ID: <1icij0INNdhc@news.cerf.net>
  10. NNTP-Posting-Host: nic.cerf.net
  11.  
  12. I wish to define a class in a library which the library user
  13. can create by dynamic allocation via the new operator, but
  14. I want to prevent him from creating automic instances.
  15.  
  16. I thought that giving the class a public new operator,
  17. but a private constructor would work, but this prevents
  18. any instances of either type from being created.
  19.  
  20. I suppose writing a satic member function called "createSomething"
  21. which would then call a private constructor via new woulod work,
  22. but it seems a little kludgy. I want my library users to create
  23. their objects using new, as our creator intended, rather 
  24. than calling some   non-standard function. Has anyone got this 
  25. to work simply by manipulating the visibility of the 
  26. existing functions.
  27.  
  28. I am reliably informed that if I wanted the inverse (i.e allow
  29. automic instances but dissallow dynamic creation) then making
  30. new private but the constructor public would work.
  31.  
  32.     tanx,
  33.         hlf
  34.  
  35.