When should I write the keyword 'inline' for a function/method?

后端 未结 15 2454
清歌不尽
清歌不尽 2020-11-21 06:55

When should I write the keyword inline for a function/method in C++?

After seeing some answers, some related questions:

  • When should I <

15条回答
  •  礼貌的吻别
    2020-11-21 07:12

    Inline keyword requests the compiler to replace the function call with the body of the function ,it first evaluates the expression and then passed.It reduces the function call overhead as there is no need to store the return address and stack memory is not required for function arguments.

    When to use:

    • To Improve performance
    • To reduce call overhead .
    • As it's just a request to the compiler, certain functions won't be inlined *large functions
      • functions having too many conditional arguments
      • recursive code and code with loops etc.

提交回复
热议问题