0

このコード スニペットを実行して、問題をテストします。

#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;
}

そして、出力を得ました:

do something 0

オブジェクトを削除した後にオブジェクトメソッドを呼び出すことができる理由を説明してくれる人はいますか?

4

0 に答える 0