关于c ++:error:没有用于调用’std :: map的匹配函数

error: no matching function for call to 'std::map

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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: error: no matching function for call to 'std::map, std::allocator > >::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, std::_Select1st >, _Compare, typename _Alloc::rebind >::other>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const std::pair&) [with _Key = int, _Tp = UserDBAInfo_t, _Compare = std::less, _Alloc = std::allocator >]
/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, std::_Select1st >, _Compare, typename _Alloc::rebind >::other>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::insert(typename std::_Rb_tree<_Key, std::pair, std::_Select1st >, _Compare, typename _Alloc::rebind >::other>::iterator, const std::pair&) [with _Key = int, _Tp = UserDBAInfo_t, _Compare = std::less, _Alloc = std::allocator >]

可能有什么问题?


the error message,indicates to that the no matching function for call to 'std::map, std::allocator > >::insert(int&, UserDBAInfo_t&),我的问题是:在茶行P></

1
structUserDBInfo.mapUserDBAInfo.insert(nDatabaseID, structUserDBAInfo);

你不是在你在线的上述问题。that should be:P></

1
structUserDBInfo.mapUserDBAInfo.insert(make_pair(nDatabaseID, structUserDBAInfo));

如果你能在11到使用C++编译器,使用:You can alsoP></

1
structUserDBInfo.mapUserDBAInfo.emplace(nDatabaseID, structUserDBAInfo);