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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:54:10+00:00 2026-05-27T01:54:10+00:00

Firstly, i am sorry if the title does not properly describe my problem, but

  • 0

Firstly, i am sorry if the title does not properly describe my problem, but i could not think of a better one. =/

I am trying to make a game where all entities that I need to draw on the screen are children of an Actor class.

The actor class has a virtual function called “virtual void drawMe()” that is overridden by the children to specify how it should be drawn.

Ergo, at the end of the game loop, I want to draw all actors. I created a “vector allActors” to help me with this and every time I create a new actor I do this: “allActors.push_back( &newActor )“. So far so good (I think).

To draw them at the end of the loop I iterate through all elements in allActors and call “allActors[i]->drawMe()” for each one.

But I discovered that this method will not work for actors that I created locally, like the bullets created when the character shoots (they are created inside an if statement).
I think it is because while I save the address of the bullets in the allActors vector, the actors themselves are destroyed after the if statement ends, so it’s an address to nothing.

example:

if ( characterShot == true)
{
    Bullet newBullet;
    allActors.push_back( &newBullet );
    characterShot = false;
}

I have no idea of how to do this in a way that it works, because I can only create the bullet actors IF the character shoots!

Please help me figure out a better and more functional way to do what I want.

Thank you in advance!

  • 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-27T01:54:10+00:00Added an answer on May 27, 2026 at 1:54 am

    Allocate the object dynamically:

    allActors.push_back(new Bullet);
    

    Note that the lifetime management will be a genuine nightmare; you should make the container elements some sort of smart pointer (ideally std::unique_ptr<Bullet> or some suitable base class).

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

Sidebar

Related Questions

Firstly, I feel sorry about the title, I do not know how to describe
Greetings, everyone: Firstly, sorry that my Flow description is long winded, but I think
Firstly, sorry about the question title, it may not be very descriptive for my
I am sorry if the title is unclear. Allow me to elaborate further. Firstly,
NOTE : My problem is NOT that my links are not being replaced. But,
Firstly, sorry for the wording of the question. I'm not too sure how to
Firstly I asked sorry if this is a stupid question. but I have a
Firstly, sorry about the long question... but this is doing my head in. Any
Hi sorry if the name of my question is not correct. i am trying
Firstly sorry for the long piece of code pasted below. This is my first

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.