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

  1. Path: sparky!uunet!wupost!spool.mu.edu!olivea!sgigate!odin!roadrunner.denver.sgi.com!bruceb
  2. From: bruceb@roadrunner.denver.sgi.com (Bruce Bailey)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: >>>>>>>>  Is it possible to use 'delete this' ?
  5. Message-ID: <1992Dec31.195705.11377@odin.corp.sgi.com>
  6. Date: 31 Dec 92 19:57:05 GMT
  7. References: <ssimmons.725636801@convex.convex.com> <796@ulogic.UUCP>
  8. Sender: news@odin.corp.sgi.com (Net News)
  9. Organization: Silicon Graphics, Inc.
  10. Lines: 25
  11. Nntp-Posting-Host: roadrunner.denver.sgi.com
  12.  
  13. In article <796@ulogic.UUCP>, hartman@ulogic.UUCP (Richard M. Hartman)
  14. writes:
  15. |> 
  16. |> Is it possible, within the definition of a class, to ensure that
  17. |> the object may only be successfully created by "new" and not
  18. |> by a simple declaration?
  19. |> 
  20. |> e.g.
  21. |> 
  22. |>     Object *p = new Object;        // ok
  23. |>     Object O;                    // fails
  24. |> 
  25. |> 
  26. |> It would be nice if we could make a constructor such that
  27. |> the second declaration gets flagged as an error, but out
  28. |> of curiosity -- even if that is not possible is it possible
  29. |> to create a class that at least generates a run time error
  30. |> if you try to create one non-dymically?
  31. |> 
  32.  
  33. I think that if you make the destructor private, the compiler will give
  34. you an error when the object goes out of scope, e.g., when you leave the
  35. function that the declaration is in...
  36.  
  37. Bruce Bailey (bruceb@denver.sgi.com)
  38.