gpt4 book ai didi

c++ - 为什么插入 map 会失败?

转载 作者:搜寻专家 更新时间:2023-10-31 01:58:09 26 4
gpt4 key购买 nike

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

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<int, int> )。这给了我以下错误:

/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()) ? liter->second : -liter->second);

有什么问题?

最佳答案

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

关于c++ - 为什么插入 map<int, int> 会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4528796/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com