aix下,stl问题

柳承枫 2014-01-17 02:27:54
keym_map.insert(pair <string, STRU_KEYM> (strKey, pstru_keym));
代码就这一行,用的stl map,报了错误,修改无效,请教高手
编译环境AIX xlC stl map
"mapopt.cpp", line 45.21: 1540-0218 (S) The call does not match any parameter list for "pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,stru_keym>::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,stru_keym>".
"/usr/vacpp/include/utility", line 70.9: 1540-1283 (I) "std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,stru_keym>::pair()" is not a viable candidate.
"mapopt.cpp", line 45.21: 1540-0215 (I) The wrong number of arguments have been specified for "std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,stru_keym>::pair()".
"/usr/vacpp/include/utility", line 72.9: 1540-1283 (I) "std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,stru_keym>::pair(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &, const stru_keym &)" is not a viable candidate.
"mapopt.cpp", line 45.55: 1540-0256 (I) A parameter of type "const stru_keym &" cannot be initialized with an expression of type "STRU_KEYM *".
"/usr/vacpp/include/utility", line 75.17: 1540-1283 (I) "template std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,stru_keym>::pair(const pair<_U1,_U2> &)" is not a viable candidate.
...全文
243 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
ri_aje 2014-01-20
  • 打赏
  • 举报
回复
引用 14 楼 jackyleu 的回复:
[quote=引用 13 楼 Jim_King_2000 的回复:] 能告诉我keym_map,strKey以及pstru_keym的定义吗?
typedef struct stru_keym { char cMode; char sztime[3 + 1]; char szKey [42 + 1]; char szData[42 + 1]; }STRU_KEYM; typedef map<string, STRU_KEYM> KEYM_MAP; strKey 就是结构里面的szKey.[/quote] strKey 是 char 数组的话,会和 map 的键类型不匹配,把它转化成 string 类型后再试一下。
柳承枫 2014-01-20
  • 打赏
  • 举报
回复
引用 25 楼 u013061236 的回复:
[quote=引用 23 楼 jackyleu 的回复:] [quote=引用 20 楼 Jim_King_2000 的回复:] 把你的代码注释掉,然后加上下面两行,看看还出错么?
map<string, int> xxx;
	xxx.insert(make_pair(string("aa"), 45));
还是出错的[/quote] 这个是map的最基本用法,根据这报的错查查吧[/quote] 问题解决了,谢谢
心是菩提树 2014-01-20
  • 打赏
  • 举报
回复
引用 23 楼 jackyleu 的回复:
[quote=引用 20 楼 Jim_King_2000 的回复:] 把你的代码注释掉,然后加上下面两行,看看还出错么?
map<string, int> xxx;
	xxx.insert(make_pair(string("aa"), 45));
还是出错的[/quote] 这个是map的最基本用法,根据这报的错查查吧
柳承枫 2014-01-20
  • 打赏
  • 举报
回复
引用 21 楼 ri_aje 的回复:
[quote=引用 14 楼 jackyleu 的回复:] [quote=引用 13 楼 Jim_King_2000 的回复:] 能告诉我keym_map,strKey以及pstru_keym的定义吗?
typedef struct stru_keym { char cMode; char sztime[3 + 1]; char szKey [42 + 1]; char szData[42 + 1]; }STRU_KEYM; typedef map<string, STRU_KEYM> KEYM_MAP; strKey 就是结构里面的szKey.[/quote] strKey 是 char 数组的话,会和 map 的键类型不匹配,把它转化成 string 类型后再试一下。[/quote] 我的key是外面另赋值的,key不在这个数组里面
柳承枫 2014-01-20
  • 打赏
  • 举报
回复
引用 20 楼 Jim_King_2000 的回复:
把你的代码注释掉,然后加上下面两行,看看还出错么?
map<string, int> xxx;
	xxx.insert(make_pair(string("aa"), 45));
还是出错的
柳承枫 2014-01-20
  • 打赏
  • 举报
回复
引用 19 楼 nanjun520 的回复:
就是[]数组一样的操作 相当于往一个数组对象里面赋值 map[key]=vlue
一开始就是这样,不行的
Jim_King_2000 2014-01-17
  • 打赏
  • 举报
回复
把你的代码注释掉,然后加上下面两行,看看还出错么?
map<string, int> xxx;
	xxx.insert(make_pair(string("aa"), 45));
nanjun520 2014-01-17
  • 打赏
  • 举报
回复
就是[]数组一样的操作 相当于往一个数组对象里面赋值 map[key]=vlue
柳承枫 2014-01-17
  • 打赏
  • 举报
回复
引用 15 楼 zbplusplus 的回复:
用【】就可以了,还有问题就要检查类型定义了 我长期在ibm hp sun上搞,基本的东西是兼容的
【】这个是什么?
柳承枫 2014-01-17
  • 打赏
  • 举报
回复
引用 16 楼 Jim_King_2000 的回复:
用了下面这行之后,报什么错?
keym_map.insert(make_pair(strKey, *pstru_keym));
"/usr/vacpp/include/functional", line 151.29: 1540-0218 (S) The call does not match any parameter list for "operator<". "/usr/vacpp/include/utility", line 89.14: 1540-1283 (I) "template <class _T1, class _T2> std::operator<(const pair<_T1,_T2> &, const pair<_T1,_T2> &)" is not a viable candidate. "/usr/vacpp/include/xutility", line 321.14: 1540-1283 (I) "template <class _Ty, class _D, class _Pt, class _Rt, class _Pt2, class _Rt2> std::operator<(const _Ptrit<_Ty,_D,_Pt,_Rt,_Pt,_Rt> &, const _Ptrit<_Ty,_D,_Pt2,_Rt2,_Pt,_Rt> &)" is not a viable candidate. "/usr/vacpp/include/xutility", line 436.14: 1540-1283 (I) "template <class _RI> std::operator<(const reverse_iterator<_RI> &, const reverse_iterator<_RI> &)" is not a viable candidate. "/usr/vacpp/include/xtree", line 455.14: 1540-1283 (I) "template <class _Tr> std::operator<(const _Tree<_Tr> &, const _Tree<_Tr> &)" is not a viable candidate. "/usr/vacpp/include/list", line 432.14: 1540-1283 (I) "template <class _Ty, class _A> std::operator<(const list<_Ty,_A> &, const list<_Ty,_A> &)" is not a viable candidate. "/usr/vacpp/include/deque", line 550.14: 1540-1283 (I) "template <class _Ty, class _A> std::operator<(const deque<_Ty,_A> &, const deque<_Ty,_A> &)" is not a viable candidate. "/usr/vacpp/include/vector", line 333.14: 1540-1283 (I) "template <class _Ty, class _A> std::operator<(const vector<_Ty,_A> &, const vector<_Ty,_A> &)" is not a viable candidate. "/usr/vacpp/include/queue", line 113.14: 1540-1283 (I) "template <class _Ty, class _C> std::operator<(const queue<_Ty,_C> &, const queue<_Ty,_C> &)" is not a viable candidate. "/usr/vacpp/include/functional", line 150.14: 1540-0700 (I) The previous message was produced while processing "std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::operator()(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &) const". "/usr/vacpp/include/xtree.t", line 93.30: 1540-0700 (I) The previous message was produced while processing "std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,stru_keym,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> >,stru_keym> >,0> >::insert(const value_type &)". "mapopt.cpp", line 46.13: 1540-0700 (I) The previous message was produced while processing "CThreadManager::Insert_keym(STRU_KEYM *)". make: The error code from the last command is 1.
Jim_King_2000 2014-01-17
  • 打赏
  • 举报
回复
用了下面这行之后,报什么错?
keym_map.insert(make_pair(strKey, *pstru_keym));
柳承枫 2014-01-17
  • 打赏
  • 举报
回复
引用 13 楼 Jim_King_2000 的回复:
能告诉我keym_map,strKey以及pstru_keym的定义吗?
typedef struct stru_keym { char cMode; char sztime[3 + 1]; char szKey [42 + 1]; char szData[42 + 1]; }STRU_KEYM; typedef map<string, STRU_KEYM> KEYM_MAP; strKey 就是结构里面的szKey.
Jim_King_2000 2014-01-17
  • 打赏
  • 举报
回复
能告诉我keym_map,strKey以及pstru_keym的定义吗?
柳承枫 2014-01-17
  • 打赏
  • 举报
回复
没人知道吗,可以加分的
柳承枫 2014-01-17
  • 打赏
  • 举报
回复
引用 2 楼 Jim_King_2000 的回复:
pstru_keym是指针。应该dereference一下。
keym_map.insert(make_pair(strKey, *pstru_keym));
这样也不行的
柳承枫 2014-01-17
  • 打赏
  • 举报
回复
引用 9 楼 sduxiaoxiang 的回复:
[quote=引用 8 楼 jackyleu 的回复:] [quote=引用 6 楼 mujiok2003 的回复:] 使用std::make_pair,不要自己生成pair
keym_map.insert(std::make_pair(strKey, *pstru_keym)); 这样写后,也是编译不过,xlC是否编译stl的东西,需要加什么参数?[/quote] 一直用stl的东东,编译时也没加过任何参数,一直正常 曾经在aix上用jni时貌似遇到过一次,不过不记得怎么解决的了[/quote] 麻烦高手帮忙想想问题解决办法,项目很紧张,谢谢
sduxiaoxiang 2014-01-17
  • 打赏
  • 举报
回复
引用 8 楼 jackyleu 的回复:
[quote=引用 6 楼 mujiok2003 的回复:] 使用std::make_pair,不要自己生成pair
keym_map.insert(std::make_pair(strKey, *pstru_keym)); 这样写后,也是编译不过,xlC是否编译stl的东西,需要加什么参数?[/quote] 一直用stl的东东,编译时也没加过任何参数,一直正常 曾经在aix上用jni时貌似遇到过一次,不过不记得怎么解决的了
柳承枫 2014-01-17
  • 打赏
  • 举报
回复
引用 6 楼 mujiok2003 的回复:
使用std::make_pair,不要自己生成pair
keym_map.insert(std::make_pair(strKey, *pstru_keym)); 这样写后,也是编译不过,xlC是否编译stl的东西,需要加什么参数?
柳承枫 2014-01-17
  • 打赏
  • 举报
回复
引用 3 楼 mujiok2003 的回复:
也可以使用std::map::operator[]
这个好像也不行
mujiok2003 2014-01-17
  • 打赏
  • 举报
回复
使用std::make_pair,不要自己生成pair
加载更多回复(5)

64,651

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧