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

后端 未结 15 2939
清歌不尽
清歌不尽 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

    Unless you are writing a library or have special reasons, you can forget about inline and use link-time optimization instead. It removes the requirement that a function definition must be in a header for it to be considered for inlining across compilation units, which is precisely what inline allows.

    (But see Is there any reason why not to use link time optimization?)

提交回复
热议问题