There may have been some misunderstanding regarding the value of the inline specifier. Yes, this gives a hint to the compiler that it would be preferable to embed the code instead of making a call, but the compiler is not forced to obey this hint. The main use of the inline specifier is to avoid breaking the rules of one definition .
Once you declare an inline function, it must be defined in each translation unit used, and the definition must be exactly the same every time. This is the opposite of what your title suggests - choosing where you define the function indicates whether it should be marked inline or not.
1) and 2) in order. In the first case, it is implicitly inline , and in the second you explicitly declared it like this. The definition is the same everywhere you include the title.
Case 3) will only work if you compile and merge X_impl.h as the source file. In this case, there will be only one definition, and inline will be redundant. Thus, the compiler does not see the definition in other translation units, and this makes its built-in function impossible, regardless of whether it is inline or not.
If the purpose of X_impl.h was to reduce the visual size of the header, then you should do it the other way around, include it at the end of Xh . inline should remain in this case.
source share