On 10/22/13 9:20 AM, blazb wrote:
> Why does the linker (gcc, msvc) not fail for the example below?
>
> It complains for multiple definitions of function bar, but not for multiple definitions of function foo in class Foo.
>
>
As has been mentioned, Foo::foo is declared (implicitly) inline. Now
inline functions may need to generate a "real" version of the function
to call when it can't be made inline for some reason, and the compiler
is obligated to make this work. Typically, the compiler will mark the
object code generated in some way so the linker will throw out the extra
copies automatically.