I read this line in Stroustrup’s book:
“An i n l i n e function (§7.1.1, §10.2.9) must be defined – by identical definitions (§9.2.3) – in every translation unit in which it is used.”
What is the rationale behind “inline function need to be DEFINED in all tranlation units”?
Am I understanding it incorrectly? I know that with other functions declarations in all the translation units except one(that contains definition) would be fine.
Historically, C++ language compilers were built on principles of independent translation. Each translation unit is compiled completely independently (and only the linker sees the entire program).
Under these circumstances, in order to perform inlining the compiler has to be able to see the source code of the function in each translation unit where it is called. For that, it has to be defined (i.e. declared with a body) in each translation unit.