I am working a with a c
library inside my c++
code. Their API
requires me passing a certain function pointer with a given signature. Let's say it's something like the following:
typedef int (*api_fun_t)(int);
What I want to be able to do is to pass function pointers that depend on certain parameters that are determined at runtime. Initially I thought of defining something like the following:
api_fun_t my_specialized_fun(int param){
int fun(int x){
// decide what to do based on param
}
return fun;
}
but problem c++
does not allow nested function definition. Next I figured I can achieve this via templates like the following
template <int param>
fun (int x){
//decide what to do based on param
}
Is there any other way of doing this that does not involve global and/or static variables?