Boost logo

Ublas :

Subject: Re: [ublas] Is there a special reason to use inline before template functions?
From: Dima Sorkin (dsorkin_at_[hidden])
Date: 2008-12-09 03:50:15

Quoting Andreas Klöckner <lists_at_[hidden]>:

> Two points:
> - ...
> - If the compiler decides to not inline, then multiple definitions of that
> function will be found by the linker. This violates the ODR and the linker
> will complain. *Unless* that function is declared inline, which makes it ok.
> So it actually has a purpose, even though it's not what its name suggests.
Yes, exactly, that is the reason to have `inline' in all template libraries as
long as old compilers exist. I sure had hard times solving this problem of
template functions not declared inline in on MIPSpro7.4.3m with SGI's STL.

I'm not sure, but I think "standard" C++ compiler should complain on multiple
definition when it did instantiate a non `inline'-marked function in several
compilation modules. I believe GCC does it too.