fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class MyClass {
  5. public:
  6. void function1(){ cout << "function1 called on object " << this << endl; }
  7. void function2(){ cout << "function2 called on object " << this << endl; }
  8. void function3(){ cout << "function3 called on object " << this << endl; }
  9. void function4(){ cout << "function4 called on object " << this << endl; }
  10. };
  11.  
  12. MyClass globalglass;
  13.  
  14. void global_function_call(void (MyClass::*method)())
  15. {
  16. (globalglass.*method)();
  17. }
  18.  
  19. int main()
  20. {
  21. cout << "address of globalglass: " << &globalglass << endl;
  22.  
  23. global_function_call(&MyClass::function1);
  24. global_function_call(&MyClass::function2);
  25. global_function_call(&MyClass::function3);
  26. global_function_call(&MyClass::function4);
  27.  
  28. return 1;
  29. }
Runtime error #stdin #stdout 0s 5672KB
stdin
Standard input is empty
stdout
address of globalglass: 0x55a2f205e131
function1 called on object 0x55a2f205e131
function2 called on object 0x55a2f205e131
function3 called on object 0x55a2f205e131
function4 called on object 0x55a2f205e131