home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!spool.mu.edu!olivea!sgigate!odin!roadrunner.denver.sgi.com!bruceb
- From: bruceb@roadrunner.denver.sgi.com (Bruce Bailey)
- Newsgroups: comp.lang.c++
- Subject: Re: >>>>>>>> Is it possible to use 'delete this' ?
- Message-ID: <1992Dec31.195705.11377@odin.corp.sgi.com>
- Date: 31 Dec 92 19:57:05 GMT
- References: <ssimmons.725636801@convex.convex.com> <796@ulogic.UUCP>
- Sender: news@odin.corp.sgi.com (Net News)
- Organization: Silicon Graphics, Inc.
- Lines: 25
- Nntp-Posting-Host: roadrunner.denver.sgi.com
-
- In article <796@ulogic.UUCP>, hartman@ulogic.UUCP (Richard M. Hartman)
- writes:
- |>
- |> Is it possible, within the definition of a class, to ensure that
- |> the object may only be successfully created by "new" and not
- |> by a simple declaration?
- |>
- |> e.g.
- |>
- |> Object *p = new Object; // ok
- |> Object O; // fails
- |>
- |>
- |> It would be nice if we could make a constructor such that
- |> the second declaration gets flagged as an error, but out
- |> of curiosity -- even if that is not possible is it possible
- |> to create a class that at least generates a run time error
- |> if you try to create one non-dymically?
- |>
-
- I think that if you make the destructor private, the compiler will give
- you an error when the object goes out of scope, e.g., when you leave the
- function that the declaration is in...
-
- Bruce Bailey (bruceb@denver.sgi.com)
-