gpt4 book ai didi

c++ - 通过迭代器更改对象

转载 作者:行者123 更新时间:2023-11-27 23:57:12 26 4
gpt4 key购买 nike

<分区>

我尝试使用迭代器更改对象,但出现此错误:

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) );

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