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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:54:38+00:00 2026-05-19T00:54:38+00:00

I have a bunch of classes in a basic (and badly coded!) game engine

  • 0

I have a bunch of classes in a basic (and badly coded!) game engine that are currently instantiated in the code and have to have their individual update functions called. What I want to do is be able to create an instance of a class, pass the name to an array, and then subsequently cycle through the array to call the update functions of each class. I’m unsure as to whether or not this is an impossible or spectacularly stupid way of trying to manage objects, so please tell me if it is.

So currently I might have manually instantiated Enemy class a couple of times:

Enemy enem1;
Enemy enem2;

I then have to update them manually in the game loop:

enem1.update();
enem2.update();

What method should I use to be able to spawn and destroy instances of the enemy class during gametime? Is it possible to populate an array with instantiated names and then do something like (and i’m aware this doesn’t work);

array[x].update();

Then iterate through the names in the array?

Anything that even points me in the right direction would be greatly appreciated!

  • 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-19T00:54:39+00:00Added an answer on May 19, 2026 at 12:54 am
    //vector initialization
    std::vector<Enemy> enemies;
    enemies.push_back(enem1);
    enemies.push_back(enem2);
    enemies.push_back(enem3);
    enemies.push_back(enem4);
    
    //update code
    for(std::vector<Enemy>::iterator e = enemies.begin() ; e != enemies.end() ; e++ )
    {
        //treat 'e' as if it's a pointer to Enemy!
        e->update(); //this will be called for each enemy in the vector 'enemies';
    }
    

    An alternative of this for loop is this:

    //update code
    for(std::vector<Enemy>::size_type i = 0 ; i < enemies.size() ; i++ )
    {
        //using index
        enemies[i].update();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.