I'm writing a memory management library and need to call a destructor explicitly, in my design I have a pointer which points to the destuctor method of a object, I write code like this:
void (*p)() = foo.~Foo;
but I got
error: cannot convert ‘Foo::~Foo’ from type ‘void (Foo::)() noexcept’ to type ‘void (*)()’
I tried some other format like void (Foo:: (*p))() noexcept = foo.~Foo; but failed.
So what is the right way to assignment a destructor to a pointer?
Edit: at runtime my code do not know what a type it is in my heap, so I can't use foo.~Foo(). I need a generate pointer which fits for all destructors, is this possible?