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?
template<> inline UINT AFXAPI HashKey<const error_code &> (const error_code & 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<UINT>(result);
}
I would get the error if the above function is placed in error_code.h
error C2912: explicit specialization; 'UINT HashKey(const error_code &)' is not a specialization of a function template
Some reference source on why I need to do the above template specialization. http://www.codeproject.com/KB/architecture/cmap_howto.aspx. The below code are picked from the article, and it is part of MFC source code.
// inside <afxtemp.h>
template<class ARG_KEY>
AFX_INLINE UINT AFXAPI HashKey(ARG_KEY key)
{
// default identity hash - works for most primitive values
return (DWORD)(((DWORD_PTR)key)>>4);
}