I assume your requirement is more complicated than your example because you don't need function pointers to solve it as written.

You can have a simple function pointer to a free function or a static member function. Simple function pointers cannot reference a member function because they lack the "this" pointer to the instance of the object.

There are several approaches to this. One is in the TR1 extensions to the C++ library:
Qt Code:
  1. #include <tr1/functional>
  2.  
  3. int C::Fun(int i){
  4. std::tr1::function<int(int,int)> pFun;
  5. if(i==1)
  6. pFun = std::tr1::bind(&C::First,
  7. this,
  8. std::tr1::placeholders::_1,
  9. std::tr1::placeholders::_2);
  10. else
  11. pFun = std::tr1::bind(&C::Second,
  12. this,
  13. std::tr1::placeholders::_1,
  14. std::tr1::placeholders::_2);
  15. return pFun(1,2);
  16. }
To copy to clipboard, switch view to plain text mode