title: Template specialization for static function when compiling with g++
body: <p>Why does the following code not work when compiling with:</p>
  
  <pre>
  $ g++ temp_main.cpp temp_spec.cpp
  /tmp/ccirjc3Y.o:temp_spec.cpp:(.text+0x100): multiple definition of `my::say()'
  /tmp/ccSo7IVO.o:temp_main.cpp:(.text$_ZN2myILi0EE3sayEv[my::say()]+0x0):
  first defined here collect2: ld returned 1 exit status
  </pre>
  
  <p>I'm trying to have specialization of static function only when using
  paramteter 0.</p>
  
  <p><strong>temp_gen.h:</strong></p>
  
  <pre><code>#ifndef temp_gen_h
  #define temp_gen_h
  
  #include &lt;iostream&gt;
  
  template&lt;int N&gt;
  struct my
  {
     static void say();
  };
  
  template&lt;int N&gt;
  void my&lt;N&gt;::say()
  {
     std::cout &lt;&lt; "generic " &lt;&lt; N &lt;&lt; std::endl;
  }
  
  #endif
  </code></pre>
  
  <p><strong>temp_spec.h:</strong></p>
  
  <pre><code>#ifndef temp_spec_h
  #define temp_spec_h
  
  #include &lt;iostream&gt;
  
  #include "temp_gen.h"
  
  template&lt;&gt;
  void my&lt;0&gt;::say()
  {
     std::cout &lt;&lt; "specialized " &lt;&lt; 0 &lt;&lt; std::endl;
  }
  
  #endif
  </code></pre>
  
  <p><strong>temp_spec.cpp:</strong></p>
  
  <pre><code>#include "temp_spec.h"
  </code></pre>
  
  <p><strong>temp_main.cpp:</strong></p>
  
  <pre><code>#include "temp_gen.h"
  
  int main(int argc, char* argv[])
  {
     my&lt;0&gt;::say();  //should say "specialized 0"
     my&lt;1&gt;::say();  //should say "generic 0"
  }
  </code></pre>