模版元递归实现阶乘

  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. }
 





posted @ 2015-07-16 18:59  指上弹兵赵小括  阅读(205)  评论(0编辑  收藏  举报