Delete and NULL

Login to reply to this topic.
Thu, 2008-01-03 12:18
Joined: 2007-07-31
Forum posts: 123

hi all,
Please clear my doubt.
I want to know in the following code

void fun()
{
CTest *test = new (ELeave) CTest();

delete test;
test = NULL;
}

when we deleted the pointer test
then what test = NULL; this statement does?
and is it correct...

Brajesh...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++


Thu, 2008-01-03 13:40
Joined: 2007-09-20
Forum posts: 95
Re: Delete and NULL

After deletion the pointer is set to NULL, to avoid any problem if it is deleted again by mistake.

Deleting a pointer twice, causes exception. Inorder to avoid this pointers are assigned to NULL after deletion. This is done to have robust program.


Chao,
Raghav

Thu, 2008-01-03 18:34
Joined: 2007-09-23
Forum posts: 132
Re: Delete and NULL

It is only necessary *if* the pointer could be deleted again.

Many people do it in a destructor where it is totally unnecessary. Don't do it in a destructor.

Fri, 2008-01-04 07:15
Joined: 2007-07-31
Forum posts: 123
Re: Delete and NULL

Thanks....


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

  • Login to reply to this topic.