Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7550745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:17:39+00:00 2026-05-30T10:17:39+00:00

I have an stl set with objects of Cell class class Cell { public:

  • 0

I have an stl set with objects of Cell class

class Cell
{
public:
    //Ctor/Dtor
    Cell(size_t cellId=0,int x =0,int y = 0,size_t t = 0):m_cellId(cellId),m_x(x),m_y(y),m_t(t),m_color(WHITE),m_pCellId(0),m_regNum(0){}
    ////////////////////
    //    Mutators    //
    ////////////////////
    void schedNode(size_t t,int nodeId){m_sched[t] = nodeId;}
    void setColor(color c){m_color = c;}
    void setParentId(size_t pId){m_pCellId = pId;}
         //.....
}

Each Cell has m_x and m_y (member) coordinates + additional data members(m_t,m_color,m_pCellId,m_regNum)

comapareCells class is used to find the cell only based on its actual m_x and m_y coordinates:

class comapareCells
{
public:
    bool operator()(const Cell& lCell,const Cell& rCell)
    {
        if(lCell.getX() < rCell.getX())
            return true;
        else if(lCell.getX() == rCell.getX())
            return (lCell.getY() < rCell.getY());
        else
            return false;
    }

};

I run the following in order to find “actual cell”:
c is a cell which has only needed cell coordinates. It is used to find the actual cell, contained in the cet, having given coordinates and try to make some operations on the actual cell:

set<Cell,comapareCells>::iterator itCell;
    if((itCell = m_cells.find(c)) == m_cells.end())
        return;
    if(itCell->getColor() != WHITE)
        return;
    itCell->setColor(GRAY);
    itCell->setParentId(cIdFrom);

I get compilation error/s foritCell->setColor(GRAY); itCell->setParentId(cIdFrom);:

cannot convert ‘this’ pointer from ‘const Cell’ to ‘Cell &’

How can it be solved?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:17:41+00:00Added an answer on May 30, 2026 at 10:17 am

    It is not legal to change the value of a set‘s elements through an iterator because the set has no way of knowing what you have changed and would invalidate it. If you want to change it like that you would have to remove it and reinsert it with your changes.

    Cell newCell(*itCell);
    newCell.setColor(GRAY);
    m_cells.erase(itCell);
    m_cells.insert(newCell);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stl::list containing Widget class objects. They need to be sorted according
I have a class which has two attributes : set< int > ens1_; set<
I have a C++ STL set with a custom ordering defined. The idea was
If i have a stl map from string to int and i want to
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I'm having some trouble in declaring a STL Set of pointers to class instances.
I have the following functor: class ComparatorClass { public: bool operator () (SimulatedDiskFile *
I am learning STL now. I read about set container. I have question when
I have a container class (called Atom) that I want to store objects of
i have written a sample program.below: #include<iostream> #include<string> #include<set> using namespace std; int main()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.