S
Sachin Midha
Hi,
I just saw someone code something like this...
int y;
class a{
public:
int x;
void f(){
y=1;
delete this;
g();
x=5;
}
void g(){}
};
Can someone please let me know what consequences would {delete this}
have on the code following that line?
What I feel is that, since functions are not allocated memory(shared
between all the objects of a class), call to g() would be done
successfully, but the code x=5, would cause a segmentation fault,
since it has no memory allocated(since object has been deleted).
But then, somebody told me that if I look at the assembly level,
delete calls a routine, and when it returns, it is lost & causes a
crash in the application. So, I am really confused, please help me
understand this.
Thanks,
Sachin
I just saw someone code something like this...
int y;
class a{
public:
int x;
void f(){
y=1;
delete this;
g();
x=5;
}
void g(){}
};
Can someone please let me know what consequences would {delete this}
have on the code following that line?
What I feel is that, since functions are not allocated memory(shared
between all the objects of a class), call to g() would be done
successfully, but the code x=5, would cause a segmentation fault,
since it has no memory allocated(since object has been deleted).
But then, somebody told me that if I look at the assembly level,
delete calls a routine, and when it returns, it is lost & causes a
crash in the application. So, I am really confused, please help me
understand this.
Thanks,
Sachin