I am posting this because i couldn't understand a bit how the boost tutorials work.

I have a class whose objects are elements of a boost multi\_index container.

I need to update the member variables of objects using member functions. I don't know how to do that. could you help me please.
I prepared a simple example:

```
#include <string>
#include <iostream>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include<vector>

using boost::multi_index::multi_index_container;
using boost::multi_index::ordered_non_unique;
using boost::multi_index::ordered_unique;
using boost::multi_index::indexed_by;
using boost::multi_index::member;

class employee_entry
{
public:
   employee_entry( const std::string& first,
                   const std::string& last,
                   long id):
                   first_name_(first),
                   last_name_(last),
                   id_(id)
   {}
   void change(){id_++;}//causing the problem
   std::string first_name_;
   std::string last_name_;
   std::vector<int> mySet;
   long id_;

   std::vector<int>::iterator mySet_begin()  {return mySet.begin();   }
};

typedef multi_index_container<
employee_entry, indexed_by<
   ordered_unique<member<employee_entry, std::string, &employee_entry::first_name_> >
   , ordered_non_unique<member<employee_entry, std::string, &employee_entry::last_name_> >
   , ordered_non_unique<member<employee_entry, long, &employee_entry::id_> >
   >
> employee_set;

//employee set.... multi-index
employee_set m_employees;

int main()
{
   using boost::multi_index::nth_index;
   using boost::multi_index::get;

   typedef nth_index<employee_set, 0>::type first_name_view;
   first_name_view& fnv = get<0>(m_employees);

   fnv.insert(employee_entry("John", "Smith", 110));
   fnv.insert(employee_entry("Fudge", "Hunk", 97));

   ///get employees sorted by id
   typedef nth_index<employee_set, 2>::type id_view;
   id_view& idv = get <2> (m_employees);
   for(id_view::reverse_iterator it = idv.rbegin(), it_end(idv.rend()); it != it_end; ++it)
   {
       std::cout << it->first_name_  <<" "
                 << it->last_name_ << ":"
                 << it->id_ << std::endl;
       it->change();//calling the troublesome function
   }

   return 0;
}

```

the error generated is:

```
 $c++ dr_function.cpp 
dr_function.cpp: In function ‘int main()’:
dr_function.cpp:65:19: error: passing ‘const employee_entry’ as ‘this’ argument of ‘void employee_entry::change()’ discards qualifiers [-fpermissive]

```
['https://Stackoverflow.com/questions/10754359', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/805896/']
The solution you posted won't work: at best it'll get a garbled index and at worst your app will crash. As your last index depends on `employee_entry::id_`, you just cannot change it liberally because you're implicitly breaking the index order. For this kind of stuff Boost.MultiIndex provides updating functions `replace` and `modify`, as discussed [here](http://www.boost.org/libs/multi_index/doc/tutorial/basics.html#ord_updating). In your particular case, you can call your `change` member function as follows:

```
idv.modify(idv.iterator_to(*it),boost::bind(&employee_entry::change,_1));

```

A bit of explanation: `idv.iterator_to(*it)` is just converting your reverse iterator into a regular iterator, which is what `modify` needs. As for the `boost::bind` part, this encapsulates `&employee_entry::change` into a suitable modifying functor. This way, you let Boost.MultiIndex know about the upcoming change in `id_` and update the indices accordingly.
well, I am answering my question at least to debug the above mentioned code. My main concern was discussed and answered in the comments below the question.
I the following code, I made `long id_` as `mutable` and changed `void change(){...}` to `void change()const{...}`

```
#include <string>
#include <iostream>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include<vector>

using boost::multi_index::multi_index_container;
using boost::multi_index::ordered_non_unique;
using boost::multi_index::ordered_unique;
using boost::multi_index::indexed_by;
using boost::multi_index::member;

class employee_entry
{
public:
   employee_entry( const std::string& first,
                   const std::string& last,
                   long id):
                   first_name_(first),
                   last_name_(last),
                   id_(id)
   {}
   void change() const {id_++;}//causing the problem
   std::string first_name_;
   std::string last_name_;
   std::vector<int> mySet;
   mutable long id_;

   std::vector<int>::iterator mySet_begin()  {return mySet.begin();   }
};

typedef multi_index_container<
employee_entry, indexed_by<
   ordered_unique<member<employee_entry, std::string, &employee_entry::first_name_> >
   , ordered_non_unique<member<employee_entry, std::string, &employee_entry::last_name_> >
   , ordered_non_unique<member<employee_entry, long, &employee_entry::id_> >
   >
> employee_set;

//employee set.... multi-index
employee_set m_employees;

int main()
{
   using boost::multi_index::nth_index;
   using boost::multi_index::get;

   typedef nth_index<employee_set, 0>::type first_name_view;
   first_name_view& fnv = get<0>(m_employees);

   fnv.insert(employee_entry("John", "Smith", 110));
   fnv.insert(employee_entry("Fudge", "Hunk", 97));

   ///get employees sorted by id
   typedef nth_index<employee_set, 2>::type id_view;
   id_view& idv = get <2> (m_employees);
   for(id_view::reverse_iterator it = idv.rbegin(), it_end(idv.rend()); it != it_end; ++it)
   {
       std::cout << it->first_name_  <<" "
                 << it->last_name_ << ":"
                 << it->id_ << std::endl;
       it->change();//calling the troublesome function
   }

   return 0;
}

```