Hi,
I was wondering about a problem, that might occur when you delete a class
in a method which was called by the deleted class. This is not actually a
problem I ran accross (I would probably restructure if possible). It is
rather one of those "What if" Questions.
Here is some code to explain what I mean:
class B;
class A {
private B* b;
public void registerB(B* _b) {
b=_b;
}
public void doStuff(void) {
// during this call the class will be destroyed
b->doStuff();
}
}
class B {
public A* a;
public B(A* _a) {
a=_a;
}
public void doStuff() {
delete a;
// when we return there will be no A to return to
}
}
int main(void) {
A* a = new A();
B* b = new B(a);
a->registerB(b);
a->doStuff();
return 0;
}
Is this undefined behaviour or are there any safety measures in the
language, like returning to the last existing caller or anything?
Till
--
Please add "Salt and Peper" to the subject line to bypass my spam filter