为什么这个插入到map失败?

发布于 2024-10-09 06:51:34 字数 1556 浏览 0 评论 0原文

我正在使用 Bison 编写一个解析器,并使用映射进行语义评估。 在其中一个函数中,我有以下代码:

map<int, int>* result = new map<int, int>();
map<int, int>::iterator liter;
map<int, int>::iterator riter;

liter = lval.polyMap.begin();
riter = rval.polyMap.begin();
l = liter->first;
r = riter->first;
(*result).insert(l, (booleanCondition()) ? liter->second : -liter->second);

(polyMap 的类型为 map)。 这给了我以下错误:

/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_tree.h: In member functio
n `void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(
_II, _II) [with _InputIterator = int, _Key = int, _Val = std::pair<const int, in
t>, _KeyOfValue = std::_Select1st<std::pair<const int, int> >, _Compare = std::l
ess<int>, _Alloc = std::allocator<std::pair<const int, int> >]':

/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_map.h:397:   instantiated
 from `void std::map<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _Input
Iterator) [with _InputIterator = int, _Key = int, _Tp = int, _Compare = std::les
s<int>, _Alloc = std::allocator<std::pair<const int, int> >]'
polynom.ypp:147:   instantiated from here

/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_tree.h:996: error: invali
d type argument of `unary *'

其中 polynom.ypp 第 147 行包含 (*result).insert(l, (booleanCondition()) ? litre->second : -liter->second);

有什么问题吗?

I'm writing a parser using Bison, and am using a map for semantic evaluation.
In one of the functions I have the following code:

map<int, int>* result = new map<int, int>();
map<int, int>::iterator liter;
map<int, int>::iterator riter;

liter = lval.polyMap.begin();
riter = rval.polyMap.begin();
l = liter->first;
r = riter->first;
(*result).insert(l, (booleanCondition()) ? liter->second : -liter->second);

(polyMap is of type map<int, int>).
And this gives me the following errors:

/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_tree.h: In member functio
n `void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(
_II, _II) [with _InputIterator = int, _Key = int, _Val = std::pair<const int, in
t>, _KeyOfValue = std::_Select1st<std::pair<const int, int> >, _Compare = std::l
ess<int>, _Alloc = std::allocator<std::pair<const int, int> >]':

/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_map.h:397:   instantiated
 from `void std::map<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _Input
Iterator) [with _InputIterator = int, _Key = int, _Tp = int, _Compare = std::les
s<int>, _Alloc = std::allocator<std::pair<const int, int> >]'
polynom.ypp:147:   instantiated from here

/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_tree.h:996: error: invali
d type argument of `unary *'

Where polynom.ypp line 147 contains (*result).insert(l, (booleanCondition()) ? liter->second : -liter->second);

What's the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菊凝晚露 2024-10-16 06:51:34

您可能需要调用 (*result).insert(make_pair(l, (booleanCondition()) ? litre->second : -liter->second));

You might want to call (*result).insert(make_pair(l, (booleanCondition()) ? liter->second : -liter->second));

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文