Should I put inline in the declaration, definition, or both?

Essentially, making a function inline is just a suggestion to the compiler. You only use the inline function for the forward declaration. On the flip side, you have some responsibilities to your compiler if you want to do this.

§ 7.1.2

2 A function declaration ( 8.3.5 , 9.3 , 11.3 ) 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

3 A function defined within a class definition is an inline function. The inline specifier shall not appear on a block scope function declaration. 94 If the inline specifier is used in a friend declaration, that declaration shall be a definition or the function shall have previously been declared inline.

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 ). [ Note: A call to the inline function may be encountered before its definition appears in the translation unit. —end note ] If the definition of a function appears in a translation unit before its first declaration as inline, the program is ill-formed. If a function with external linkage is declared inline in one translation unit, it shall be declared inline in all translation units in which it appears; no diagnostic is required. An inline function with external linkage shall have the same address in all translation units. A static local variable in an extern inline function always refers to the same object. A type defined within the body of an extern inline function is the same type in every translation unit.

/r/cpp_questions Thread