lundi 7 août 2017

object in a map iterator

void setTable(map<int,int>);

Table.h file

 void Table::setTable(map<int,int> table) 
    {
        this->mapTable = table;
    }

Table.cpp file

void updateTable(set<Table> & setTable)
    {

    for (set<Table>::iterator it=setTable.begin(); it!=setTable.end(); ++it)
    {
            //it returns a map that is correspond to map<int,int>
            map<int,int> mapTable = it->getTable();

            for(map<int, int>::iterator p = mapTable.begin();p != mapTable.end();p++)
            {
                if(p->first <= newPeerID)
                {
                    mapft[p->first] = newPeerID;
                    changes = true;
                }
                else if (p->first > newPeerID)
                {   
                    if(changes == true)
                    {
                       //line 68, unable to call the member function
                        it->setTable(mapft);
                        changes = false;
                    }
                    break;

                }
            }

        }
}

ownTable.cpp: In function ‘void updateTable(std::set&)’: ownTable.cpp:68:33: error: passing ‘const Table’ as ‘this’ argument of ‘void Table::setTable(std::map)’ discards qualifiers [-fpermissive] it->setTable(mapft);

"Objects in an std::set are necessarily const, since they are used as keys. When an object (or reference) is constant, you can only call member functions of that object which are declared with the const qualifier."

But i am unable to set my accessor function as const since the value does not change the during execution. If that is the case, is there a way that i can call setTable function in Table class so that i can update my map

Aucun commentaire:

Enregistrer un commentaire