Have global function definition in header file, and avoid duplicated symbol linkage error
<p>I have the following code in a header only file.</p>

<pre><code>#pragma once

class error_code {
public:
    unsigned __int64 hi;
    unsigned __int64 lo;    
};

std::ostream&amp; operator&lt;&lt; (std::ostream&amp; o, const error_code&amp; e) {
    return o &lt;&lt; "[" &lt;&lt; e.hi &lt;&lt; "," &lt;&lt; e.lo &lt;&lt; "]";
}
</code></pre>

<p>I get linkage error, when there are 2 cpp in the project include this header file.</p>

<blockquote>
  <p>error LNK2005: "class error_code
  __cdecl operator|(class error_code const &amp;,class ViTrox::error_code const
  &amp;)" (??U@@YA?AVerror_code@0@ABV10@0@Z)
  already defined in xxx.obj</p>
</blockquote>

<p>I know I can resolve this problem, if I move the definition of <code>operator&lt;&lt;</code> to a cpp file, or to a DLL file. </p>

<p>However, I just would like to have them in a <strong>SINGLE</strong> header file. Is there any technique to achieve so? Or must I separate the definition to another file?</p>
