I was a bit late with this answer, but since the problem is that you could take this step later using the template version for your callback registration function, and the other for regular function pointers:
template<typename C> void RegisterCallback(void (C::* func)(int, bool), C* inst) { MyCallback callback(boost::bind(func, inst, _1,_2)); } void RegisterCallback(void (*func)(int, bool)) { MyCallback callback(func); } A * myA = new A(); RegisterCallback(&A::GoodCallback, myA); RegisterCallback(&A::BadCallback, myA);
This works as expected in VS2010, but lacks the need for not one, but two callback registration functions to work correctly with member functions and non-members.
As another option, you can look at the boost_types library. It provides the metafunction parameter_types, which retrieves the parameter types of function pointers and returns them as an MPL sequence. Then, using the matte magic of the template, you can check the parameters of the callback function, for example:
#include <boost/function.hpp> #include <boost/bind.hpp> #include <boost/function_types/parameter_types.hpp> #include <boost/mpl/equal.hpp> using namespace boost; using namespace boost::function_types; template< typename Function > void RegisterCallback(Function f) { BOOST_MPL_ASSERT(( mpl::equal< parameter_types< Function >, parameter_types< void(int,bool) > > )); MyCallback callback(f); } template<typename Function, typename T> void RegisterCallback(Function f, T* inst) { BOOST_MPL_ASSERT(( mpl::equal< parameter_types< Function >, parameter_types< void (T::*)(int,bool) > > )); MyCallback callback(boost::bind(f, inst, _1, _2)); }
This also works as expected in VS2010, but you still need two function declarations, although you can pack them into one if you define them inside the structure (and use the default template parameter argument for T);