Two questions about inline functions in C++

前端 未结 6 1108
情书的邮戳
情书的邮戳 2021-01-13 17:09

I have question when I compile an inline function in C++.

Can a recursive function work with inline. If yes then please describe how.

I am sure about loop

6条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 17:49

    Remember that the inline key word merely sends a request, not a command to the compiler. The compliler may ignore yhis request if the function definition is too long or too complicated and compile the function as normal function.

    in some of the cases where inline functions may not work are

    1. For functions returning values, if a loop, a switch or a goto exists.
    2. For functions not returning values, if a return statement exists.
    3. If function contains static variables.
    4. If in line functions are recursive.

    hence in C++ inline recursive functions may not work.

提交回复
热议问题