so i am doing a inventory program. I have a vector of class items in it and I want to user enter Id and then run an iterator to match with the Id that is in the vector and change the value of the quantity sold:
here is part of my code:
vector<Item>::const_iterator it;
for(it=items.begin(); it !=items.end(); it++){
if (it->getID() == id){
amount=it->getactual()-sold;
it->setactual(amount);
that is in my class
int getactual()const{return actual_quantity;}
void setactual(int quantity){actual_quantity=quantity;}
but i get an error: passing ‘const Item’ as ‘this’ argument of ‘void Item::setactual(int)’ discards qualifiers
You should use
instead of
const_iteratormeans read-only.