code_junkie

C++, equivalence between pointer-to-functions and pointer-to-member-functions?

Nov 13th, 2011
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. boost::function f<(void)(MyObject*, int, int)> = &MyObject::method_that_takes_two_ints;
  2.  
  3. void (MyObject::*f)( int, int ) = &MyObject::method_that_takes_two_ints;
  4.  
  5. void (MyObject::*f)( int, int ) = &MyObject::method_that_takes_two_ints;
  6.  
  7. MyObject o; (o.*f)(1, 2);
  8.  
  9. int main() {
  10. typedef void fun() const;
  11. fun MyObject::*mem_function_ptr =
  12. &MyObject::const_method_that_takes_two_ints;
  13. }
  14.  
  15. void foo() { cout << "hello"; }
  16. int main() {
  17. typedef void fun();
  18. fun * f = &foo;
  19. }
  20.  
  21. struct A {
  22. operator int() const { return 0; }
  23. };
  24.  
  25. int main() {
  26. A a;
  27. int i = a; // implicit conversion using the conversion function
  28. }
Add Comment
Please, Sign In to add comment