home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!ulogic!hartman
- From: hartman@ulogic.UUCP (Richard M. Hartman)
- Newsgroups: comp.lang.c++
- Subject: Re: >>>>>>>> Is it possible to use 'delete this' ?
- Message-ID: <796@ulogic.UUCP>
- Date: 31 Dec 92 00:46:54 GMT
- References: <ssimmons.725636801@convex.convex.com>
- Organization: negligable
- Lines: 31
-
- In article <ssimmons.725636801@convex.convex.com> ssimmons@convex.com (Steve Simmons) writes:
- >On page 66 of the ARM, there is an example of why you would want the
- >"delete this" capability. Therefore, it is probably legal. However,
- >the standard does also say that you must be careful not to delete
- >a pointer that is not allocated by new. The resulting behavior is
- >undefined (maybe nothing or maybe core dump).
-
-
- 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?
-
-
- -Richard Hartman
- hartman@ulogic.COM
-
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- "Fosters! It's Australian for beer, mate!"
-
-