Search code examples
c++inline-functions

Inlining C++ code


Is there any difference to the following code:

class Foo  
{
  inline int SomeFunc() { return 42; }
  int AnotherFunc() { return 42; }
};

Will both functions gets inlined? Does inline actually make any difference? Are there any rules on when you should or shouldn't inline code? I often use the AnotherFunc syntax (accessors for example) but I rarely specify inline directly.


Solution

  • Both forms should be inlined in the exact same way. Inline is implicit for function bodies defined in a class definition.