I have struggled heaps to teach myself C++. One of the keys of my clear concepts are making a lot of mistakes. And I mean A LOT!
In my last article [ilike in C++ same as SQL] (click here to read) I made changes. Because writing an article means a lot to me. It simply means that I am helping someone clear their concepts. Initially, I had derived std::string for sake of function extensions and then I realized I should not; since it is not recommended to derive from standard string. So, I was porting functions from derived string to utility string functions. While, I was doing that I came across this issue of choosing between having an inline function vs having a class with static functions.
In C++, inline functions are a lot like placeholder. Means, when you define them, compiler will replace the function call with actual code. You might ask yourself, then what are inline functions good for? Well, short answer is, they save time and hassle of writing code again. Also, make code more clearer and faster. (Faster [for small in-line functions] because it does not have to go to v-table and find definition)
Size of Inline Function
Size of inline functions have big impact on efficiency. Bigger the inline function is, lower the efficiency would be. Take a look at following example
This code is simple enough to explain what happens under the hood. So when compiler compiles line 7 it actually replace that function call with actual code. So, after compilation, main funciton looks like:
What are cons of above code? It will eventually get slower depending on number of lines the inline function has. Compiler will replace each function call with the actual code, eventually replacing a lot of lines with a lot of more lines. The above calls line 2-4 will not cause too much of trouble. main function will look like