I have this code
void foo(int Var1, int Var2, int default1=10, int defaul2=10);
void bar(int Var1, int Var2);
someFunction(void (*foobar)(int, int));
otherFunction(void (*foobar)(int, int, int, int));
int main(){
someFunction(foo); //ERROR
otherFunction(bar); //ERROR
}
So, i want to choose between foo and bar on the same function ignoring the default parameters, but i don't know how to do it.
It won't work because foo's function signature doesn't correspond to what someFunction expects. The default parameters in foo don't make the parameters go away, it just fills it with a default value at compile time.
You could try casting foo and see what that gives you.
typedef void (*twoParameterFunctionType)(int, int);
someFunction((twoParamterFunctionType)foo);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.