Destructor not called after destroying object placement-new'ed

后端 未结 3 755
予麋鹿
予麋鹿 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 15:00

    Change your explicit destructor call to

    this->~Function();
    

    Currently the ~Function is constructing a "Function" and then calling the ~ bitwise operator, (legal because you have a conversion to bool), and then destructing that, not the called object.

提交回复
热议问题