Почему эта вставка в картупотерпит неудачу? - PullRequest
2 голосов
/ 25 декабря 2010

Я пишу парсер, используя 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 *'

Где строка 147 polynom.ypp содержит (*result).insert(l, (booleanCondition()) ? liter->second : -liter->second);

В чем проблема?

1 Ответ

3 голосов
/ 25 декабря 2010

Возможно, вы захотите позвонить (*result).insert(make_pair(l, (booleanCondition()) ? liter->second : -liter->second));

...