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:注意:候选者是: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:注意: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 <_键,_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 >>]
可能有什么问题?
1 回答
错误消息
no matching function for call to 'std::map, std::allocator > >::insert(int&, UserDBAInfo_t&)
向我表明问题在于:不是你在问题中提到的那一行 . 那应该是:
如果您能够使用C 11编译器,您还可以使用: