//TMP(模板元编程),计算阶乘
#include <iostream>
using namespace std;
template <unsigned n>
struct Factorial
{
enum
{
value = n * Factorial<n - 1>::value
};
};
//偏特化
template <>
struct Factorial<0>
{
enum
{
value = 1
};
};
int main()
{
cout << Factorial<5>::value << endl;
cout << Factorial<10>::value << endl;
return 0;
}
计算阶乘,你见过这样的么?
最新推荐文章于 2022-02-18 16:22:08 发布