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

  1. Newsgroups: comp.lang.c++
  2. From: nikki@trmphrst.demon.co.uk (Nikki Locke)
  3. Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
  4. Subject: Re: How to prevent local instances, but allow "new"
  5. Reply-To: nikki@trmphrst.demon.co.uk
  6. References: <1icij0INNdhc@news.cerf.net>
  7. Distribution: world
  8. X-Mailer: cppnews $Revision: 1.30 $
  9. Organization: Trumphurst Ltd.
  10. Lines: 16
  11. Date: Wed, 6 Jan 1993 12:22:34 +0000
  12. Message-ID: <726348154snx@trmphrst.demon.co.uk>
  13. Sender: usenet@demon.co.uk
  14.  
  15. In article <1icij0INNdhc@news.cerf.net> hlf@nic.cerf.net (Howard Ferguson) 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. Leave the constructors public. Make the DESTRUCTOR private. Provide an
  21. inline member function ... 
  22.  
  23.     void destroy() { delete this; }
  24.  
  25. Users have to call destroy instead of delete, but they won't be able to
  26. create automatic, static or extern objects of the class.
  27.  
  28. -- 
  29. Nikki Locke,Trumphurst Ltd.(PC and Unix consultancy) nikki@trmphrst.demon.co.uk
  30. trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.
  31.