Later I create an instance of W2
I have : W2 * my_w2 as private , and I create it so : my_w2 = new W2;
I have some functions to do the work :;
1 do
2.- Create the instance my_w2 = new w2;
3,4, ... 6general code to do some things.
7 w2->my_w1.w1 = 99;
8. delete my_w2;
9 print my:w2->my_w1.w1
// incredible I'd have to take an error but ... not
// I have : 99 ????
9 loop
I have discover that when delete my_w2 keeps my_w1 information ????
How can I delete my_w2 effectively ?
Thanks
when you use delete, the compiler arranges for the appropriate destructors to be called, then informs the OS that we are finished with the block of memory.
The OS merely marks the memory block as free - it does not have to do anything else and certainly it does not have to do anything immediately.
So if you do what you did, and immediately try to use the object again, you may find valid values.
It is up to you (the programmer) NOT to try to use the pointer again - you called delete and so
you should consider the object as DEAD
Thanks g.
But, How can I delete it?
(I have written the print my_w2->my_w1.w1 to know what is happen, but I dont need this instruction)
I have the my_w2 = new w2 and there is no NEW execution, because it keeps data .... no delete was executed efectivelly.....