fork download
  1. #include <iostream>
  2. #include <boost/bind.hpp>
  3.  
  4. // Declare a static function pointer type
  5. typedef void (*MyStaticFunctionPtr)(int);
  6.  
  7. // Define a static function that takes an integer argument
  8. static void myStaticFunction(int x)
  9. {
  10. std::cout << "Static function called with argument " << x << std::endl;
  11. }
  12.  
  13. // Define a class with a member function that takes an integer argument
  14. class MyClass
  15. {
  16. public:
  17. void myMemberFunction(int x)
  18. {
  19. std::cout << "Member function called with argument " << x << std::endl;
  20. }
  21. };
  22.  
  23. int main()
  24. {
  25. // Create a static function pointer and call the static function
  26. MyStaticFunctionPtr ptr = &myStaticFunction;
  27. ptr(10);
  28.  
  29. // Create an instance of MyClass and call its member function using boost::bind
  30. MyClass obj;
  31. auto boundFunc = boost::bind(&MyClass::myMemberFunction, &obj, _1);
  32. boundFunc(20);
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5564KB
stdin
Standard input is empty
stdout
Static function called with argument 10
Member function called with argument 20