Class static function external linkage
<p>How can achieve external linkage for class static functions when the compiler thinks the code is local linkage or inline? </p>

<p>Consider three files:</p>

<p>traits.h:</p>

<pre><code>template &lt;typename T&gt;
struct Traits
{
    static int InlineFunction(T);
    static int Function(T);
};
</code></pre>

<p>traitsimp.cpp:</p>

<pre><code>#include "traits.h"
template &lt;&gt;
struct Traits&lt;int&gt;
{
    static int InlineFunction(int) { return 42; }
    static int Function(int);
};

int Traits&lt;int&gt;::Function(int i) { return i; }
</code></pre>

<p>main.cpp:</p>

<pre><code>#include "traits.h"
int main()
{
    int result = Traits&lt;int&gt;::Function(5);
    result = Traits&lt;int&gt;::InlineFunction(result);
    return 0;
}
</code></pre>

<p>When compiled receives:</p>

<pre><code>$ g++ traitsimp.cpp main.cpp -o traitstest
/tmp/cc6taAop.o: In function `main':
main.cpp:(.text+0x1b): undefined reference to `Traits&lt;int&gt;::InlineFunction(int)'
collect2: ld returned 1 exit status
</code></pre>

<p>How do I convince the compiler to give InlineFunction external linkage while still writing the function within the class definition?</p>
