fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. template<unsigned int N>
  7. class Factorial
  8. {
  9. public:
  10. static const int value = Factorial<N-1>::value*N;
  11. };
  12.  
  13. template<>
  14. class Factorial<0>
  15. {
  16. public:
  17. static const int value = 1;
  18. };
  19.  
  20.  
  21. int main()
  22. {
  23. cout << Factorial<5>::value << endl;
  24. vector<int> v;
  25. v.push_back(Factorial<6>::value);
  26. cout << v[0] << endl;
  27. }
  28.  
Success #stdin #stdout 0s 15224KB
stdin
Standard input is empty
stdout
120
720