daily pastebin goal
46%
SHARE
TWEET

template factorial

bogolyubskiyalexey Feb 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3.  
  4. template <int n>
  5. struct Factorial {
  6.     static int Value() {
  7.         return Factorial<n - 1>::Value() * n;
  8.     }
  9. };
  10.  
  11. template<>
  12. struct Factorial<1> {
  13.     static int Value() {
  14.         return 1;
  15.     }
  16. };
  17.  
  18. int main() {
  19.     std::cout << Factorial<3>::Value() << std::endl;
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top