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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:24:45+00:00 2026-05-27T07:24:45+00:00

I store pointers to all instances of class Cell in a linked list. The

  • 0

I store pointers to all instances of class Cell in a linked list. The std::list<Cell*> cells is stored in a class named Game. The method Game::update() iterates trought all instances of Cell held in the list cells, and calls each cell’s Cell::update() method. If the Cell::update() method finds out at some point that the cell is ready to divide, it needs to push_back() a pointer to the new cell to cells in order for the new cell to be updateable.
But how can I refer to Game::cells within the cell in order to do that? I have considered the following options:

  • Defining std::list<Cell*> cells in global scope instead.
    • nasty and makes it impossible to have more than one Game
  • Making std::list<Cell*> cells a static member of Cell
    • better than the global var but still prevents the use of multiple Game instances
  • Passing a reference to the current game’s Game::cells as a parameter to the Cell’s constructor and subsequently storing a copy of that reference in the newly constructed cell instance
    • I think it is a little inflexible
  • Passing a reference to the current game’s Game::cells as a parameter to the Cell::update() method

Are there more elegant solutions to utilize?

  • 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-27T07:24:46+00:00Added an answer on May 27, 2026 at 7:24 am

    I would not introduce an unnecessary dependence between Cell and Game, if all Game does is to call methods on Cells and hold instances of them.

    You could instead return new Cells (or none) from Cell::update() and let Game decide what to do, most probably add them to the list. You could also define a new function for this in Cell, something like Cell::splitCell() and let Cell::update() only update properties of Cell objects (as the name would suggest).

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

Sidebar

Related Questions

I would like to store pointers to a Base class in a vector ,
In my app, i've created the TList type list where i store the pointers
Let's say I want to store a group of function pointers in a List<(*func)>
I would like to store instances of several classes in a vector. Since all
I am using boost::any to store pointers and was wondering if there was a
I'm trying to store member function pointers by templates like this: (This is a
Implementing a custom VM and I've come to use registers (these will store pointers
I need help with pointers and memory management. I need to store different objects,
I'm making a game right now and pretty much everything has its own class.
At the moment I am using a vector to store pointers to the object

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.