Edit to account for the fact that f cannot be modified:
Since you can't modify f, the only solution I can think of is using some sort of global variable together with a forwarding function:
int bar(int i, MyClass * mc);
namespace bar_parameters
{
MyClass * mc = 0;
}
int binded_bar(int i)
{
return bar(i, bar_parameters::mc);
}
int main()
{
MyClass myclass(input);
bar_parameters::mc = &myclass;
double retval = f(binded_bar);
}
This is quite ugly, however...
It is not possible to bind parameters of a function. However, it is possible with functor (function object).
The first thing you need to do is to modify f's parameter to make it a function object such as std::function or boost::function, instead of a function pointer:
double f(std::function<int (int)> foo);
You can use this function either with function pointers or functors with the correct signature.
After that, you can use binding methods such as std/boost::bind (or bind1st/bind2nd in C++03):
double retval = f(std::bind(bar, _1, &myclass));
If you don't have access to Boost or C++0x, you can use the usual technique which consists in making the parameter template in order to accept any callable entities (function pointers and functors):
template <typename Func>
double f(Func foo);
The drawback of this approach is that the signature of the function is only enforced by the way you use it in f.
To bind the second parameter, you can then use ptr_fun to convert a function pointer to a function object, and bind2nd to actually bind the parameter:
double retval = f(std::bind2nd(std::ptr_fun(bar), &myclass));
int) as a parameter of your function call or is that just a bad name choice for some variable ?