recursive template instantiation exceeded maximum depth of 256

前端 未结 3 1758
無奈伤痛
無奈伤痛 2021-01-17 17:27

I was trying to rewrite the Factorial implementation using constexpr function but for some reason I have no idea why I get a compile error:

3条回答
  •  春和景丽
    2021-01-17 18:01

    When N == 0, the compiler still has to instantiate f2<-1> because the function call is present in the code. When f<-1> is instantiated, f<-2> is instantiated and so on. Applying this statement again and again, the compiler will keep recursing through the template until it exceeds the max depth.

提交回复
热议问题