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
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.
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.
As I recall the destructor cannot be called explicitely. Try moving the cleanup code from destructor to other function and call it instead.