Those three options are all corrects.
After it depends on such thing :
If your function is quite short (like getters/setters), it is more common to see the function directly defined in the class definition.
If your function is bigger, it can be good to define it in another header and include only this header in the source where the function is used. This will only speed up your compilation. But It is rare to inline
big function.
But don't forget that, it is not because you used the inline
keyword that your compile will inline your function. It is up to the compiler to decide if it will the function in every place it use or not.
This is stated explicitly in the standard :
7.1.2/2 Function specifiers [dcl.fct.spec]
A function declaration with an inline
specifier declares an inline function. The inline specifier indicates to the implementation that inline substitution of the function body at the point of call is to be preferred to the usual function call mechanism. An implementation is not required to perform this inline substitution at the point of call; however, even if this inline substitution is omitted, the other rules for inline functions defined by 7.1.2 shall still be respected.
Last thing :
Most compilers already optimize code to generate inline functions when it is more convenient. This specifier only indicates the compiler that inline is preferred for this function.
As jrok stated, inline
is mainly used to avoid violation of the One Definition Rule. Here we can also quote a little part of the standard :
(§ 7.1.2/4) An inline function shall be defined in every translation unit in which it is odr-used and shall have exactly the same definition in every case (3.2).
3.2 One definition rule [basic.def.odr]
No translation unit shall contain more than one definition of any variable, function, class type, enumeration type, or template.