Is delete this allowed?

后端 未结 10 1382
-上瘾入骨i
-上瘾入骨i 2020-11-22 03:40

Is it allowed to delete this; if the delete-statement is the last statement that will be executed on that instance of the class? Of course I\'m sure that the ob

10条回答
  •  [愿得一人]
    2020-11-22 04:20

    Well, in Component Object Model (COM) delete this construction can be a part of Release method that is called whenever you want to release aquisited object:

    void IMyInterface::Release()
    {
        --instanceCount;
        if(instanceCount == 0)
            delete this;
    }
    

提交回复
热议问题