Binding a method with an object pointer and deleting the object afterwards, the method is still callable.
struct A {
void b(){std::cout << "SUHDU" << std::endl;}
};
int main(int argc, const char * argv[])
{
A *a = new A;
auto f1 = std::bind(&A::b, a);
auto f2 = std::bind(&A::b, std::ref(a));
f1();
f2();
delete a;
f1(); // still outputs SUHDU
f2(); // still outputs SUHDU
}
Why does std::bind
behave this way and how does it do it?