模版元递归实现阶乘
#include<iostream>
usingnamespace std;
template<unsigned n>
structFactorial
{
enum{value = n *Factorial< n -1>::value};
};
template<>
structFactorial<0>
{
enum{value =1};
};
int main()
{
cout <<Factorial<3>::value << endl;
return0;
}
#include<iostream>
usingnamespace std;
template<unsigned n>
structFactorial
{
enum{value = n *Factorial< n -1>::value};
};
template<>
structFactorial<0>
{
enum{value =1};
};
int main()
{
cout <<Factorial<3>::value << endl;
return0;
}