An inline function, as far as I know, is a function which a compiler can replace those function definition wherever those are being called.
So, let's clear that part up.
Inline has 2 definitions:
- It tells the compiler that the function code can be expanded where the function is called, instead of effectively being called.
- It tells the compiler that the function definition can be repeated.
You are obviously thinking of definition 1. As the answer goes on to state, that definition is not really used anymore (if it was ever used). inline
to the compiler only means that the definition can be repeated. It allows you to put the definition in headers (although it may have other uses too).
So, back you your original question:
If I were to declare and define a namespace function function above the main function, as it is shown below, would that result in compiler generating it as an inline function?
Inline by your definition is only determined by the compiler. You have no control over "inlineness," in this sense of the word, whatsoever.
Of course, if you want the other definition of inline, you have to declare it inline:
namespace pairs_with_k_diff {
inline void inc_and_push_back () {
// function definition
}
}
There is no other way to get this function "inline" (in the second sense of the word) without, of course, declaring it inline
. It won't happen automatically.