So, I know that you can pass a function as an argument like so:
int a(int x) {
return x + 1;
}
int b(int (*f)(int), int x) {
return f(x); // returns x + 1
}
I also know you can have a function with default arguments, like so:
int a(int x = 1) {
return x;
}
a(2); // 2
a(); // 1
However, how do I pass a function with default arguments to a function and preserve this behavior?
I've tried the following:
int b(int (*f)(int), int x) {
f(x); // works as expected
f(); // doesn't work because there aren't enough arguments to f
}
and
int b(int (*f)()) {
f(); // doesn't work because it cannot convert int (*)(int) to int (*)()
}