本文共 601 字,大约阅读时间需要 2 分钟。
#includetemplate class Factorial{public: static int const vl = N * Factorial ::vl;};template<> class Factorial<1>{public: static int const vl = 1;};template class FactorialSum{public: static int const vl = Factorial ::vl + FactorialSum ::vl;};template<> class FactorialSum<1>{public: static int const vl = Factorial<1>::vl;};void main(){ int const N = 7; printf("%d的阶乘:%d\n", N, Factorial ::vl); printf("%d的阶乘之和:%d\n", N, FactorialSum ::vl);}
参考:http://www.cnblogs.com/winter-cn/archive/2009/09/05/1561094.html