Advertisement
a3f

small funptr example

a3f
Dec 30th, 2014
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int my_if(bool condition, void (*do_this)(), void(*do_that)())
  4. {if (condition) do_this(); else do_that();}
  5.  
  6. void print_true(){ std::cout<< "THIS IS TRUE :)" << std::endl; }
  7. void print_false(){ std::cout<< "THIS IS FALSE :(" << std::endl; }
  8.  
  9. int main()
  10. {
  11.     my_if(1==1, print_true, print_false);
  12.     // equals:
  13.     if(1==1)
  14.         print_true();
  15.     else
  16.         print_false();
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement