المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Delete doesn't ^delete^ a reference?



C++ Programming
07-26-2011, 06:31 PM
Hi,

I just found that the keyword Delete doesn't mean ^delete^ the way we(or maybe just I) normally think it does.

I thought if you delete a reference, the reference is deleted right after the delete and to have NULL value, which is not so true.

Let me show you an example.

--------------------------------------------
#include
class test
{
public:
char ch;
~test() { printf("End!\n"); }
};

class test2
{
public:
char ch2;
~test2() { printf("End!\n"); }
};

int main()
{
test* callFunc = new test();
callFunc ->ch = 'a';

delete callFunc;

test2* callFunc2 = new test2();
printf("%p %p\n",(void*)callFunc,(void*)callFunc2);
callFunc2 -> ch2 = 'b';

printf("%c %c \n",callFunc ->ch ,callFunc2 -> ch2);
}


End!
0395BA8 0395BA8
b b
--------------------------------------------

From this result, I want to theorize that the keyword Delete is just to let the references that you delete be available to be pasted later.

I'd like to know if my idea is correct or if there are some other reasons for this?

Thanks in advance.