Template Specialization in Header File
<p>I realize I have to put the below code (For template specialization) in CPP file instead of Header file? Is there any way I can make it in Header file?</p>

<pre><code>template&lt;&gt; inline UINT AFXAPI HashKey&lt;const error_code &amp;&gt; (const error_code &amp; e)
{
    // Hash code method required for MFC CMap.
    // This hash code generation method is picked from Joshua Bloch's
    // Effective Java.
    unsigned __int64 result = 17;
    result = 37 * result + e.hi;
    result = 37 * result + e.lo;
    return static_cast&lt;UINT&gt;(result);
}
</code></pre>

<p>I would get the error if the above function is placed in error_code.h</p>

<blockquote>
  <p>error C2912: explicit specialization;
  'UINT HashKey(const
  error_code &amp;)' is not a specialization
  of a function template</p>
</blockquote>

<p>Some reference source on why I need to do the above template specialization. <a href="http://www.codeproject.com/KB/architecture/cmap_howto.aspx" rel="nofollow">http://www.codeproject.com/KB/architecture/cmap_howto.aspx</a>. The below code are picked from the article, and it is part of MFC source code.</p>

<pre><code>// inside &lt;afxtemp.h&gt;

template&lt;class ARG_KEY&gt;
AFX_INLINE UINT AFXAPI HashKey(ARG_KEY key)
{
    // default identity hash - works for most primitive values

    return (DWORD)(((DWORD_PTR)key)&gt;&gt;4);
}
</code></pre>
