Я пытаюсь изменить объект, используя итератор, но я получаю эту ошибку:Изменение объекта с помощью итератора
Error 1 error C2662: 'void Item::setCount(int)' : cannot convert 'this' pointer from 'const Item' to 'Item &'
1 IntelliSense: the object has type qualifiers that are not compatible with the member function
Это мой код:
void Customer::addItem(Item other)//add item to the set
{
set<Item>::iterator it;
it = _items.find(other);
if (it != _items.end())
{
it->setCount((this->getCount((*it)) + 1));
}
else
_items.insert(other);
}
И в этой линии у меня есть ошибки :
it->setCount((this->getCount((*it)) + 1));
см. Ответ о изменяемых полях в методах const. – UmNyobe