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 7781777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:20:12+00:00 2026-06-01T19:20:12+00:00

The relevant (I think) lines of my coding are below. What is meant is

  • 0

The relevant (I think) lines of my coding are below.
What is meant is that there is a list of Clusters.
One of them, base, will absorb another one (the aborbed).
The aborbed cluster should be erased from the list.

First problem I encountered was that I needed to perform other operations in both base and absorbed clusters, after while cycle closes.
From my searches, I found the = &(*li) stuff. What I understand is that I get a pointer to the address of the element li points to, although I cannot do absorbed = li, because one is an iterator and the other a (simple?) ponter. I’d appreciate some explanation on this.

Now, the bigger problem is that I get a sementation fault in the line c->getPoints(); of the method joinCluster()
What am I doing wrong? What should I do an why?

I’m using g++ (GCC) 4.5.2 in Linux x86_64.

Cluster * base;
Cluster * absorbed;

list<Cluster>::iterator li = clusters.begin(); 
while ( li != clusters.end() ) {   
    if (li->getId() == p2) {
        absorbed = &(*li);
        li = clusters.erase(li);
    } else if (li->getId() == p1) { 
        base = &(*li);
    }
++li;
}

base->joinCluster(absorbed);


void Cluster::joinCluster(Cluster * c)
{
    set<unsigned int> pts = c->getPoints(); 
}

set<unsigned int> Cluster::getPoints()
{
return points;
}

class Cluster {
    private:
    std::set<unsigned int> points;
    public:
    std::set<unsigned int> getPoints();
};
  • 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-06-01T19:20:14+00:00Added an answer on June 1, 2026 at 7:20 pm
    list<Cluster>::iterator li = clusters.begin(); 
    while ( li != clusters.end() ) {   
        if (li->getId() == p2) {
            absorbed = &(*li);
            li = clusters.erase(li);
        } else if (li->getId() == p1) { 
            base = &(*li);
        }
    ++li;   // <----  Don't increment when you already deleted.
    }
    

    When you delete then last element in the list, li becomes cluster.end(). Then you increment it again and boom, you’re out of bounds. ++li should go in else block.

    Note also, when you erase li from the container, absorbed holds an invalid adress.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using pygame and livewires (though I don't think that part is relevant
The code below only outputs single line(there are 2 in database that should be
I am looking for a command that will accept (as input) multiple lines of
Disclaimer: I am using ExtJS 3, but I don't think it's very relevant to
Though it's on the edge of programming questions, I think this is still relevant
I need 3 tables that are all relevant to the same thing. For instance,
Relevant Tables #One# +----------+ +--------------+ |Quotations| ---> |PurchaseOrders| +----------+ | +--------------+ <One> | <Many>
Are there any relevant security issues in using a file cache (i.e. PEAR Cache_Lite)
Here is the code relevant to my question: http://jsfiddle.net/mkerny45/V23NK/ As you can see there
I'm downloading a long list of my email subject lines , with the intent

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.