1

I got a problem with a iterator. When i compile my project i keep getting this error.

Kitchen.cpp: In member function ‘void Kitchen::If_Cook_Ok(const Order&) const’:
    Kitchen.cpp:45:33: error: passing ‘const Order’ as ‘this’ argument of ‘std::list<IngredType::Ingredient> Order::getIngredient()’ discards qualifiers [-fpermissive]
    Kitchen.cpp:45:70: error: passing ‘const Order’ as ‘this’ argument of ‘std::list<IngredType::Ingredient> Order::getIngredient()’ discards qualifiers [-fpermissive]

I already tried to put constness on the function member, but i keep getting this error. Here is the code

The Order class has as member variable a std::list witch is returned by the getter getIngredients()

void    Kitchen::If_Cook_Ok(const Order &order) const
{
  std::cout << "congratulations you barely made it" << std::endl;
  std::list<IngredType::Ingredient>::const_iterator it;

  for (it = order.getIngredient().begin(); it != order.getIngredient().end(); ++it)
    {
      std::cout << *it << std::endl;
    }
}

Help will be much appreciated.

2 Answers 2

4

order is a const Order&. Thus, you could only call const methods of Order class. And it appears that Order::getIngredient() is not const.

1
  • As i responded just above you got it just right, it was the other member function that wasn't a const one, thanks a lot. Commented Apr 27, 2014 at 1:51
3

TheOrder parameter in the method If_Cook_Ok is const, so you can only call const methods on this object. Perhaps the getIngredients() method is not const. Try adding const on that method.

1
  • Indeed it was the other method that wasn't const thank you very much. Commented Apr 27, 2014 at 1:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.