错误:没有匹配函数调用'std :: map
typedef struct {
string strDatabaseName;
set <string, greater<string> > setDBAccName;
} UserDBAInfo_t;
typedef struct {
map<int, UserDBAInfo_t > mapUserDBAInfo;
} UserDBInfo_t;
typedef set<string, greater<string> > setNames_t;
int main( int argc, char * argv[] )
{
...
map<string, UserDBInfo_t > mapHRUserDBInfo;
UserDBInfo_t structUserDBInfo;
UserDBAInfo_t structUserDBAInfo;
structUserDBAInfo.strDatabaseName = strDatabaseName;
structUserDBAInfo.setDBAccName.insert(strDBAccName);
structUserDBInfo.mapUserDBAInfo.insert(nDatabaseID, structUserDBAInfo);
mapHRUserDBInfo.insert(make_pair(strSabun, structUserDBInfo)); <--- compile error here
...
}
当我编译它时,我收到错误消息。
main.cpp:2778:错误:没有匹配函数调用'std :: map <int,UserDBAInfo_t,std :: less <int>,std :: allocator <std :: pair <const int,UserDBAInfo_t>>: :insert(int&,UserDBAInfo_t&)'/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_map.h :395:note:candidates are:std :: pair <typename std :: _ Rb_tree <_Key,std :: pair <const _Key,_Tp>,std :: _ Select1st <std :: pair <const _Key,_Tp>>,_Compare ,typename _Alloc :: rebind <std :: pair <const _Key,_Tp>> :: other> :: iterator,bool> std :: map <_Key,_Tp,_Compare,_Alloc> :: insert(const std :: pair <const _Key,_Tp>&)[with _Key = int,_Tp = UserDBAInfo_t,_Compare = std :: less <int>,_Alloc = std :: allocator <std :: pair <const int,UserDBAInfo_t>>] / usr / lib / gcc / x86_64-redhat-linux / 4.1.2 /../../../../include/c ++/ 4.1.2 / bits / stl_map.h:419:note:typename std :: _ Rb_tree < _Key,std :: pair <const _Key,_Tp>,std :: _ Select1st <std :: pair <const _Key,_Tp>>,_Compare,typename _Alloc :: rebind <std :: pair <const _Key,_Tp>>: :other> :: iterator std :: map <_Ke y,_Tp,_Compare,_Alloc> :: insert(typename std :: _ Rb_tree <_Key,std :: pair <const _Key,_Tp>,std :: _ Select1st <std :: pair <const _Key,_Tp>>,_Compare, typename _Alloc :: rebind <std :: pair <const _Key,_Tp>> :: other> :: iterator,const std :: pair <const _Key,_Tp>&)[with _Key = int,_Tp = UserDBAInfo_t,_Compare = std :: less <int>,_Alloc = std :: allocator <std :: pair <const int,UserDBAInfo_t>>]
什么可能是错的?
错误消息, no matching function for call to 'std::map, std::allocator > >::insert(int&, UserDBAInfo_t&)
我这个问题在行中:
structUserDBInfo.mapUserDBAInfo.insert(nDatabaseID, structUserDBAInfo);
而不是你在问题中提到的那一行。 这应该是:
structUserDBInfo.mapUserDBAInfo.insert(make_pair(nDatabaseID, structUserDBAInfo));
如果您能够使用C ++ 11编译器,则还可以使用:
structUserDBInfo.mapUserDBAInfo.emplace(nDatabaseID, structUserDBAInfo);
链接地址: http://www.djcxy.com/p/73081.html
上一篇: error: no matching function for call to 'std::map
下一篇: Why does outputting a class with a conversion operator not work for std::string?