The problem is that you are calling the function as a free function, when it isn't. It's a member function, and you need to call it in the context of an object:
(obj.*f)();
Boost.Bind offers an idiomatic way to tackle this:
#include<boost/bind.hpp>
// ...
Impl i(boost::bind(&Base::fnc, obj));
You can define the Impl
constructor like so:
#include<boost/function.hpp>
// ...
Impl(boost::function<void ()> fnc)
{
fnc(); // boost::bind translates it to obj.fnc()
}
If only the Impl
object knows what object to call the function on, then you can use the placeholders of Boost.Bind:
Impl i(boost::bind(&Base::fnc, boost::_1));
And the Impl
constructor would then be similar to
Impl(boost::function<void (Base)> fnc, Base& b)
{
fnc(b); // boost::bind translates it to b.fnc()
}
Sometimes it's wiser to use templates in the side that accepts the functor:
template<class Op>
Impl(Op fnc) { ... }
because then the client can pass any member function, with or without boost. But the cost is that you might have harder-to-understand compiler error messages.