1

I am trying to create a simple wrapper function for std::bind, which will take a member function.

template<typename T, typename F>
void myBindFunction(T &t)
{
   std::bind(T::F, t );
}

MyClass a = MyClass();
myBindFunction <MyClass, &MyClass::m_Function>( a );

I'm not sure if what I am trying to achieve it possible?

James
  • 97
  • 1
  • 9

1 Answers1

1

You can make the 2nd template parameter a non-type template parameter, i.e. a member function pointer.

template<typename T, void(T::*F)()>
void myBindFunction(T &t)
{
   std::bind(F, t); // bind the member function pointer with the object t
}

LIVE

songyuanyao
  • 169,198
  • 16
  • 310
  • 405