2015-07-10 142 views
-3
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 

    ... 

} 

當我編譯它時,我收到錯誤消息。錯誤:沒有匹配函數調用'std :: map

main.cpp:2778: error: no matching function for call to '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<_Key, _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> >]

什麼可能是錯誤的?

+0

是否包含頭? – Steephen

回答

0

錯誤消息,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); 
+1

或者,如果使用C++ 11,用'emplace'替換'insert',它將把參數轉發到'make_pair' –

+0

你是對的。非常感謝。 我解決了它的幫助。 ^^ –

相關問題