模版元递归实现阶乘

  1. #include<iostream>
  2. usingnamespace std;
  3. template<unsigned n>
  4. structFactorial
  5. {
  6. enum{value = n *Factorial< n -1>::value};
  7. };
  8. template<>
  9. structFactorial<0>
  10. {
  11. enum{value =1};
  12. };
  13. int main()
  14. {
  15. cout <<Factorial<3>::value << endl;
  16. return0;
  17. }
 





原文地址:https://www.cnblogs.com/fengkang1008/p/4652205.html