Object-Oriented Suicide or delete this;

后端 未结 3 1665
闹比i
闹比i 2020-12-10 05:06

The following code compiled with MSVC9.0 runs and outputs Destructor four times, which is logical.

#include 
class SomeClass         


        
3条回答
  •  被撕碎了的回忆
    2020-12-10 05:28

    p->~SomeClass(); //line 5

    p->CommitSuicide(); //line 6

    Line (6) definitely invokes Undefined Behaviour.

    That is, is invocation of another member after the explicit call of the destructor allowed (defined)?

    No! Your assumption is correct.

提交回复
热议问题