Should “delete this” be called from within a member method?

前端 未结 12 2024
醉酒成梦
醉酒成梦 2020-12-03 10:55

I was just reading this article and wanted SO folks advice:

Q: Should delete this; be called from within a member method?

12条回答
  •  忘掉有多难
    2020-12-03 11:22

    Some threading libraries use it when implementing an auto destroy on thread termination.

    void Thread::threadFunc()
    {
        doRun();
    
        if(this->destroyOnExit == true)
            delete this;
    }
    

提交回复
热议问题