Suppose there is a function in a legacy library that I want to use that requires a function pointer as an input
void LegacyFunction(int* (*func)(float, float), int a, float b);
but the problem is it is expecting the return value of the function to be an int raw pointer instead of an int unique_ptr, meaning I can only get it to compile if my function looks like
int* MyFunc(float a, float b);
in other words, if I modify MyFunc into
std::unique_ptr<int> MyFunc(float a, float b);
and pass it into the legacy library function like
LegacyFunction(MyFunc, 1, 2.0f);
there will be a compilation error. I know if the function is taking an usual int pointer there can be some workaround using the get() function like
std::unique_ptr<int> a;
LegacyFunctionRawPointer(a.get(), 1, 2.0f);
Is there a similar workaround for function pointer input? It will be a travesty if I have to replace the unique_ptr for MyFunc with raw pointer.
MyFunca runtime value or is it known at the compile time?MyFuncin a lambda.