我是第一次尝试使用 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/