template <int N>
struct Factorial {
enum { value = N * Factorial<N - 1>::value };
};
template <>
struct Factorial<0> {
enum { value = 1 };
};
const int x = Factorial<4>::value; // == 24
const int y = Factorial<0>::value; // == 1
预编译后,如果我们能奇迹般地看到编译器产生什么样,我们将真正看到:这个模板创建的实际源代码是什么样的?
const int x = 24;
const int y = 1;
,我们将看到实际定义为struct Factorial
,这些多重?如果是这样,他们将如何看待?我试图围绕元编程过程的这一部分进行研究。
'阶乘<901> :: value'坠毁我的DEV-C++:错误:模板实例化深度超过了最大值900 – johnchen902