Infinite compilation with templates

后端 未结 4 1151
小鲜肉
小鲜肉 2021-01-05 21:07

This question is just out of curiosity. In recursive templates if we forget to put one particular specialization, then compiler will do large number of iterations and then s

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-05 21:54

    The compiler does what you ask it do do. You asked it to engage into infinite recursion - it did exactly that. If you want it to "stop at some time", you have to ask it to stop at "some time" and tell it what specific "some time" you mean exactly.

    Template recursion is not different from any other recursion in C++ program: it is your responsibility to specify where the recursion bottoms-out.

提交回复
热议问题