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

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

    In reality, pretty much never. All you're doing is suggesting that the compiler make a given function inline (e.g., replace all calls to this function /w its body). There are no guarantees, of course: the compiler may ignore the directive.

    The compiler will generally do a good job of detecting + optimizing things like this.

提交回复
热议问题