c++ - std::multimap 编译错误

标签 c++ visual-studio-2008 mfc

我是第一次尝试使用 multimap,但我的应用无法编译。 TIA 保罗..

// file dept.h

typedef std::multimap <CString, std::map< CString, CString> > _DeparmentRecord;  // also tryied replacing CString with LPCWSTR

_DeparmentRecord DeparmentRecord;


// file dept.cpp

DWORD CIni::AddNameValue(LPCWSTR Section, LPCWSTR Name, LPCWSTR Value)
{

DeparmentRecord.insert(std::make_pair ( Section, std::make_pair(Name, Value)) );  <-- error here

}

c:\program files\microsoft visual studio 9.0\vc\include\utility(57):错误 C2664:'std::map<_Kty,_Ty>::map(const std::less<_Ty> &) ':无法将参数 1 从“const std::pair<_Ty1,_Ty2>”转换为“const std::less<_Ty> &”

1> 与 1> [ 1> _Kty=CString, 1> _Ty=CString 1> ] 1> 和 1> [ 1> _Ty1=LPCWSTR, 1> _Ty2=LPCWSTR 1> ] 1> 和 1> [ 1> _Ty=CString 1> ] 1> 原因:无法从“const std::pair<_Ty1,_Ty2>”转换为“const std::less<_Ty>” 1> 与 1> [ 1> _Ty1=LPCWSTR, 1> _Ty2=LPCWSTR 1> ] 1> 和 1> [ 1> _Ty=CString 1> ] 1> 没有可用的可以执行此转换的用户定义转换运算符,或者无法调用该运算符 1> c:\dev\projects\migrator\jobbuilder\jobbuilder\ini.cpp(55) : 参见函数模板实例化的引用 'std::pair<_Ty1,_Ty2>::pair>(const std::pair> & )' 正在编译 1> 与 1> [ 1> _Ty1=const CString, 1> _Ty2=std::map 1> ]

========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========

最佳答案

按如下方式更改函数。

DWORD AddNameValue(LPCWSTR  Section, LPCWSTR  Name, LPCWSTR  Value)
{
    std::map<CString, CString> aTemp;
    aTemp.insert(std::make_pair (Name, Value));
    DeparmentRecord.insert(std::make_pair (Section, aTemp)) ;
}

关于c++ - std::multimap 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/920312/

相关文章:

c++ - 如何在 C++ 中将 CString 转换为 char?

c++ - x64 应用程序和 ActiveX 控件的问题

c++ - Dynamic_cast 对象为同一类型

visual-studio - Visual Studio 2008 Team System 中缺少源代码管理菜单项

c++ - 如何将控制台输出数据输入命令提示符?

mfc 删除默认工具栏

c++ - MFC中如何在资源链中查找资源?

c++ - 结构内的函数原型(prototype) - Intellisense 找不到

c++ - 删除另一个类的方法中的多个指针

visual-studio-2010 - Visual Studio - 是否有简单的方法将 'Close Solution"添加到解决方案资源管理器中的 r 单击