I'm trying to become an expert in linking in my spare time.
It really is
My guess as to why you "need" to put the inline function sin the "header"
file is because they must be visible when the compiler uses the class
definition.
Note that the definition of a class begins with the class heading, and ends
with the };. Even if the member functions are not defined at the time the
compiler finishes with the class body, the class is defined.
inline functions get placed directly into the object code for the routine
that invokes them. This is different than what happens with non-inline
functions. With them, all you need as a signature. The linker can take
care of finding them when they are needed.
I thought a little history might be useful. You are right as to what
inline implies, but slightly off from what it has become.
The experimental compiler (early days) would generate error for many
cases of inline. For instance, if you included a for-loop it would say,
"Sorry, for-loop not implemented for inline, yet", or something
like that.
This became annoying, and would not be easy to maintain for commercial
compilers. For instance, to remove the error (or warning) when it
became possible to do so required maintenance.
It was decided to treat inline as a request to the compiler. Thus,
compiler will do inline if it can, otherwise it will pass it on to
linker for (external) linkage.
Recently (well, a few years ago) there were some complications in
separate compilations (projects involving multiple source files)
involving C and CPP source files, with regard to inline. It was decided
to allow external linkage for inline functions, anyway. That should
explain the behavior of VC++.
Again, your statement correctly explains the linkage error. However,
there were deviations from the original intent. In the case posted
here, the particular compiler is not creating external linkage, so the
linker cannot resolve the symbol (the call). The designers are taking
your view.
Hope this helps.
Regards,
(e-mail address removed)
http://www.zhmicro.com
http://distributed-software.blogspot.com