我有一张地图,其值为 std::pair。
编译器在尝试设置迭代器时抱怨如下,但我不明白为什么:
src/DBConnector.cpp: 在成员函数'int DBConnector::createGenericInsert(std::string, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::less<std::basic_string<char, std::char_traits<char >、std::allocator<char> > >、std::allocator<std::pair<const std::basic_string<char、std::char_traits<char>、std::allocator<char> >、std::对<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::string&)': src/DBConnector.cpp:354: 错误: 否匹配 'l_oIterEnd = p_mapValues.std::map<_Key, _Tp, _Compare, _Alloc> 中的 'operator='::以 _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = std::pair<int, std::basic_string<char, std::char_traits<char 结尾>, std::allocator<char> > >, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator <std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<int, std::basic_string<char, std::char_traits< char>, std::allocator<char> > > > >' /usr/include/c++/4.4/bits/stl_map.h:251: 注意:候选者是:std::map<_Key, _Tp, _Compare, _Alloc> & std::map<_Key, _Tp, _Compare, _Alloc>::operator=(const std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = std::pair<int, std::basic_string<char, std::char_traits<字符>,std::allocator<char>>,_Compare = std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,_Alloc = std::分配器<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<int, std::basic_string<char, std::char_traits <char>, std::allocator<char> > > > >]basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]
我的功能是:
int DBConnector::createGenericInsert ( std::string p_sTable , std::map<std::string , std::pair<int,std::string> > p_mapValues , std::string & po_sInsert ) {
std::map<std::string,std::pair<int,std::string> > l_oIter;
std::map<std::string,std::pair<int,std::string> > l_oIterEnd;
std::string s_Fieldnames;
l_oIterEnd = p_mapValues.end(); // This is line 354
l_oIter = p_mapValues.begin();
s_Fieldnames += l_oIter.first();
...
}
这里有什么问题 ?地图可以包含 std::pairs 吗?(此外,地图可以包含持有不同类型的键吗?)