你要#include <afxtempl.h>  

解决方案 »

  1.   

    放心,所有头文件我都已经包括了的。我也知道用 CMapStringToString,但我现在只想知道 CMap<CString, CString&, CString, CString&> 为什么要出错?
      

  2.   

    该成CMap< CString, LPCTSTR... >
    效果一样
      

  3.   

    --------------------Configuration: Test - Win32 Debug--------------------
    Compiling...
    StdAfx.cpp
    Compiling...
    Test.cpp
    c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(129) : error C2440: 'type cast' : cannot convert from 'class CString' to 'unsigned long'
            No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
            c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1324) : see reference to function template instantiation 'unsigned int __stdcall HashKey(class CString &)' being compiled
    TestDlg.cpp
    c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(129) : error C2440: 'type cast' : cannot convert from 'class CString' to 'unsigned long'
            No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
            c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1324) : see reference to function template instantiation 'unsigned int __stdcall HashKey(class CString &)' being compiled
    Generating Code...
    Error executing cl.exe.Test.exe - 2 error(s), 0 warning(s)
      

  4.   

    人家MFC定义的CMapStringToString可是实实在在的类,而不是模板啊,人家都这样定义一定有原因吧,看看MFC源码,也许有点帮助
      

  5.   


    CMap的定义是:
    template< class KEY, class ARG_KEY, class VALUE, class ARG_VALUE >class CMap 
    可能Key必须是DWORD,int,LPTSTR...之类的简单类型,而不能是一个对象,如CString。虽说Key是一个class,但实际只能是一个数值。
      

  6.   

    但是从理论上来说,CMap 的定义中各项都是 class,我就应该可以定义为 class 才对啊?
    什么地方有相关的例子和资料,帮我找找吧!MSDN 中的例子我看过了,太简单,只用了一个 DWORD 到 String 的 Map。
      

  7.   

    编译器试图进行'class CString' to 'unsigned long',可能key只支持内建类别,
      

  8.   

    CString没有生成哈希表的函数,你得自己重载
    unsigned int __stdcall HashKey(class CString &)