Why do I get stack overflow?
Christopher Wright
dhasenan at gmail.com
Sun May 24 16:57:35 PDT 2009
Ary Borenszweig wrote:
> When I compile this code I get "stack overflow" printed in the console.
> Anyone know why?
>
> ---
> int fact(int X)() {
> if(X == 0) {
> return 1;
> } else {
> int temp = fact!(X - 1)();
> return X * temp;
> }
> }
>
> const someVar = fact!(0)();
> ---
Like Moritz said. You need to use "static if" there rather than "if".
More information about the Digitalmars-d-learn
mailing list