You, and the people here who give tips on small features, are looking at the inline old-fashioned way.
inline means "I want this code to work fast, so whenever I call this function, I want you to extend it in place to avoid the overhead of calling the function."
This is a really good optimization. Actually, it’s so good that the compiler will look forward to doing this even if you do not specify inline .
The compiler also cannot extend your inline functions. Therefore, you really do not need to worry about how this will affect performance, because the compiler can and will ignore inline if you use it stupidly.
In fact, compilers today almost always ignore your use of inline and just do whatever they think is best.
So, knowing why people still use inline ?
Currently, there is only one reason to use inline , and also to work with the Unified Definition Rule (ODR).
In C / C ++, you can only define a function once. If you do this:
int foo() { } int foo() { }
the compiler will complain that you have defined the same function twice.
This looks like a silly example, but it’s especially convenient to do something like this when you use #include - if you defined your function in the header and you #include the same header twice, that’s exactly what you are doing.
Fortunately, inline has another application that is still valid today: if you mark the function as inline , this forces the compiler to disable ODR problems, which allows you to define your function in the header.
In other words, inline now means "I want to define this function in the header."
When you look at this, it should be clear that you must remove inline when moving the function to the cpp file.
For fun, there are a couple of places where functions are implicitly made inline. One of them is included in the class functions:
struct Foo { void bar() { } };
I have seen people mention features like inline , but this is completely redundant. The compiler does it anyway; There is no need to worry about ODR, and there is no performance you can get.
Another place in the templates. Because templates must be defined in headers, they are exempt from ODR, and inline they are redundant.