I understand that I have to put the code below (for template specialization) in a CPP file instead of a header file? Is there a way to do this in the header file?
template<> inline UINT AFXAPI HashKey<const error_code &> (const error_code & e) {
I would get an 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 the function template
Some source of links on why I need to do the template specialization described above. http://www.codeproject.com/KB/architecture/cmap_howto.aspx . The code below is selected from the article, and it is part of the 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); }
source share