Destructor not called after destroying object placement-new'ed

后端 未结 3 817
予麋鹿
予麋鹿 2021-02-19 14:21

I had no clue why this doesn\'t work. The following Function is created by placement new. A function is provided that checks whether it should be destructed, and if

3条回答
  •  时光取名叫无心
    2021-02-19 14:53

    This is because ~Function(); in not a destructor call syntactically here. Use this->~Function(); instead.

    ~Function(); is parsed as an operator ~ and creation of the Function object on the stack. Function class has an operator bool that's why this will be compiled.

提交回复
热议问题