Advertisement
konalisp

weird factorial

Mar 7th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. using namespace std;
  5.  
  6. int main(int argc, char **argv){
  7.    
  8.     function<int(int)> factorial = [&factorial](int val) -> int {
  9.         if( val <= 1 ) {
  10.             return 1;
  11.         }
  12.         else {
  13.             return val * factorial(val-1);
  14.         }
  15.     }; //Note: Must be in a function body or else warnings appear.
  16.    
  17.     auto test = bind(factorial, 5); //binding!
  18.    
  19.     cout << factorial(12);
  20.     cout << endl;
  21.     cout << test();
  22.    
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement