Click here to Skip to main content
15,887,328 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionDelete doesn't ^delete^ a reference? Pin
Dean Seo25-Jul-11 20:58
Dean Seo25-Jul-11 20:58 
AnswerRe: Delete doesn't ^delete^ a reference? Pin
Richard MacCutchan25-Jul-11 21:24
mveRichard MacCutchan25-Jul-11 21:24 
GeneralRe: Delete doesn't ^delete^ a reference? Pin
Dean Seo26-Jul-11 14:11
Dean Seo26-Jul-11 14:11 
AnswerRe: Delete doesn't ^delete^ a reference? Pin
Chris Losinger26-Jul-11 1:45
professionalChris Losinger26-Jul-11 1:45 
GeneralRe: Delete doesn't ^delete^ a reference? Pin
Dean Seo26-Jul-11 14:10
Dean Seo26-Jul-11 14:10 
AnswerRe: Delete doesn't ^delete^ a reference? Pin
jschell26-Jul-11 9:48
jschell26-Jul-11 9:48 
GeneralRe: Delete doesn't ^delete^ a reference? Pin
Dean Seo26-Jul-11 14:09
Dean Seo26-Jul-11 14:09 
AnswerRe: Delete doesn't ^delete^ a reference? Pin
Stefan_Lang27-Jul-11 3:00
Stefan_Lang27-Jul-11 3:00 
new does three things:
1. allocate memory from the heap
2. initialize the object at the resulting memory location
3. return a pointer to this new object.

What it does not do is set the value of your pointer variable - this is done by the assignment operator '='.

delete does the reverse, in reverse order:
1. take a pointer to an existing object
2. destruct the object
3. deallocate the memory it occupied

What it does not is reset the value of your pointer variable.

Technically it wouldn't be so hard to make delete also reset your pointer variable to 0, but since 'cleaning up' is often done at the end of a function or the end of the scope a pointer is defined in, it is usually not neccessary.

Nevertheless it is a good idea to always explicitely set a pointer to 0 after calling delete on it! Even if your delete is the very last line in your code, someone might later add code to that function, past that line.

That said, it might have been better if the C++ standard required the delete operator to also set the pointer to 0. But it doesn't. Of course, it is possible to overwrite delete, if you really want it that way... Wink | ;)
GeneralRe: Delete doesn't ^delete^ a reference? Pin
jschell27-Jul-11 12:32
jschell27-Jul-11 12:32 
QuestionWorking with XML file in MFC Dialog based application? Pin
Le@rner25-Jul-11 20:27
Le@rner25-Jul-11 20:27 
AnswerRe: Working with XML file in MFC Dialog based application? Pin
Rajesh R Subramanian25-Jul-11 20:31
professionalRajesh R Subramanian25-Jul-11 20:31 
GeneralRe: Working with XML file in MFC Dialog based application? Pin
Le@rner25-Jul-11 21:02
Le@rner25-Jul-11 21:02 
GeneralRe: Working with XML file in MFC Dialog based application? Pin
Richard MacCutchan25-Jul-11 21:14
mveRichard MacCutchan25-Jul-11 21:14 
AnswerRe: Working with XML file in MFC Dialog based application? Pin
David Crow26-Jul-11 5:11
David Crow26-Jul-11 5:11 
GeneralRe: Working with XML file in MFC Dialog based application? Pin
Le@rner26-Jul-11 19:03
Le@rner26-Jul-11 19:03 
GeneralRe: Working with XML file in MFC Dialog based application? Pin
Rolf Kristensen27-Jul-11 12:05
Rolf Kristensen27-Jul-11 12:05 
QuestionDoes "parasoft c++ test" support VS2008? Pin
Cold_Fearing_Bird25-Jul-11 19:05
Cold_Fearing_Bird25-Jul-11 19:05 
AnswerRe: Does "parasoft c++ test" support VS2008? Pin
Code-o-mat25-Jul-11 22:07
Code-o-mat25-Jul-11 22:07 
QuestionA link problem with c++ template function Pin
Cold_Fearing_Bird25-Jul-11 15:14
Cold_Fearing_Bird25-Jul-11 15:14 
AnswerRe: A link problem with c++ template function Pin
«_Superman_»25-Jul-11 16:31
professional«_Superman_»25-Jul-11 16:31 
GeneralRe: A link problem with c++ template function Pin
Cold_Fearing_Bird25-Jul-11 17:33
Cold_Fearing_Bird25-Jul-11 17:33 
AnswerRe: A link problem with c++ template function Pin
Stefan_Lang27-Jul-11 3:29
Stefan_Lang27-Jul-11 3:29 
QuestionCan both VS2005 and 2008 be installed on XP Pin
Cold_Fearing_Bird25-Jul-11 3:51
Cold_Fearing_Bird25-Jul-11 3:51 
AnswerRe: Can both VS2005 and 2008 be installed on XP Pin
Chris Losinger25-Jul-11 3:54
professionalChris Losinger25-Jul-11 3:54 
JokeRe: Can both VS2005 and 2008 be installed on XP Pin
«_Superman_»25-Jul-11 7:11
professional«_Superman_»25-Jul-11 7:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.