为什么插入map <int,int =“”>会失败?</int,>

时间:2010-12-25 00:05:02

标签: c++ stl bison

我正在使用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<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);

有什么问题?

1 个答案:

答案 0 :(得分:3)

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