I run this code snippet to test the problem:
#include <iostream>
#include <functional>
using namespace std;
class A
{
private:
int i;
public:
A(): i(0) {}
void doSomething()
{
cout << "do something " << i << endl;
}
};
int main() {
A* a = new A();
function<void()> func = std::bind(&A::doSomething, a);
delete a;
a = nullptr;
func();
return 0;
}
And got the output:
do something 0
Could anyone help me explain why we can call an object method after deleted the object ?