摘自 effective c++
// TODO 条款48 Be aware of template metaprogramming. // [9/29/2013 xiarl]
template<unsigned n>
struct Factorial
{
enum
{
value = n* Factorial<n-1>::value
};
};
template<>
struct Factorial<0>
{
enum
{
value = 1
};
};
int _tmain(int argc, TCHAR * argv[])
{
int ivalue = Factorial<9>::value;//362880
return 0;
}