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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:26:02+00:00 2026-06-04T06:26:02+00:00

I have a Map over which I iterate like this: std::map<unsigned int, GameObject *>::iterator

  • 0

I have a Map over which I iterate like this:

std::map<unsigned int, GameObject *>::iterator itr = _gameObjects.begin();
    while (itr != _gameObjects.end())
    {
        itr->second->Update();
        itr++;
    }

Update() might insert an element into the map or even remove one from it, but it doesn’t necessarily do any of the two.
It obviously doesn’t work like that. Is there a way it can be done?

  • 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-04T06:26:03+00:00Added an answer on June 4, 2026 at 6:26 am

    From std::map::erase():

    References and iterators to the erased elements are invalidated. Other references and iterators are not affected.

    From std::map::insert():

    No iterators or references are invalidated.

    From std::map::operator[]:

    No iterators or references are invalidated.

    If Update() does not remove itself, then the code is legal. If Update() does, then it is not. Update() would be required to inform the calling code if it removed itself, either setting a flag or returning the next iterator (as suggested by Attila).

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

Sidebar

Related Questions

I have a map<string, list<int> > which I want to iterate over the list
I have a Map[Long, String] which I would like iterate over in descending order
I have this map, which I show some red markers over and whenever a
I have a MAP which is optionally of type std::map and optionally of type
On this page I have a link to a google map which opens in
First time here so I hope this makes sense! I have a Map which
I have a map which has only one input field where the user will
If I have to following HTML which is a image of a map. The
Possible Duplicate: How do I iterate over each Entry in a Map? I want
I have a Map (Int, Int) a where a can be any type. Based

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.