home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!demos!news-server
- From: David Tolpin <dat@infos.msk.su>
- Subject: Re: can I 'delete' without a 'new'?
- References: <66.66.0.999.2AA9B801@infos.msk.su>
- Date: Sun, 6 Sep 1992 17:00:05 GMT
- Reply-To: dat@infos.msk.su
- Organization: InfoSoft (Echo2News)
- Sender: news-server@kremvax.hq.demos.su
- Message-ID: <66.66.0.7.2aaa1687@infos.msk.su>
- Lines: 41
-
- Hello peter@kentrox.uucp!
-
- Friday September 04 1992 17:10, peter@kentrox.uucp wrote to All:
-
- pu:> I can't seem to find any references which indicate whether I can do this
- pu:> or not, so I'm appealing to the net.wisdom. Here's what I've got:
-
- pu:> class foo {
- pu:> char *String;
- pu:> public:
- pu:> foo();
- pu:> foo( char * );
- pu:> ~foo();
- pu:> void set( char * );
- pu:> };
-
- pu:> foo:foo() { };
-
-
- pu:> foo:~foo() {
- pu:> delete [] String;
- pu:> }
-
- pu:> The question is what will happen if I create a foo with the empty
- pu:> constructor and never call 'set'? Since 'new' has never been called,
- pu:> what will 'delete' try to delete? Looks like a real good way to frazzle
- pu:> the system. Yes? No?
-
- 1.Initialize pointers that are not allocated in the constructor. foo::foo() {
- String = NULL; }
-
- 2.After deleting a pointer that in a place other than destructor, assigns NULL
- to it.
-
- David Tolpin, Moscow, Russia
-
- --- GED
- * Origin: << David Tolpin from Northern Hills, dat@infos.msk.su > (66:66/0.7)
-
-
-
-