home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18582 < prev    next >
Encoding:
Internet Message Format  |  1992-12-30  |  1.4 KB

  1. Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!ulogic!hartman
  2. From: hartman@ulogic.UUCP (Richard M. Hartman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: >>>>>>>>  Is it possible to use 'delete this' ?
  5. Message-ID: <796@ulogic.UUCP>
  6. Date: 31 Dec 92 00:46:54 GMT
  7. References: <ssimmons.725636801@convex.convex.com>
  8. Organization: negligable
  9. Lines: 31
  10.  
  11. In article <ssimmons.725636801@convex.convex.com> ssimmons@convex.com (Steve Simmons) writes:
  12. >On page 66 of the ARM, there is an example of why you would want the 
  13. >"delete this" capability.  Therefore, it is probably legal.  However, 
  14. >the standard does also say that you must be careful not to delete 
  15. >a pointer that is not allocated by new.  The resulting behavior is 
  16. >undefined (maybe nothing or maybe core dump). 
  17.  
  18.  
  19. Is it possible, within the definition of a class, to ensure that
  20. the object may only be successfully created by "new" and not
  21. by a simple declaration?
  22.  
  23. e.g.
  24.  
  25.     Object *p = new Object;        // ok
  26.     Object O;                    // fails
  27.  
  28.  
  29. It would be nice if we could make a constructor such that
  30. the second declaration gets flagged as an error, but out
  31. of curiosity -- even if that is not possible is it possible
  32. to create a class that at least generates a run time error
  33. if you try to create one non-dymically?
  34.  
  35.  
  36.         -Richard Hartman
  37.         hartman@ulogic.COM
  38.  
  39. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  40. "Fosters!  It's Australian for beer, mate!"
  41.  
  42.