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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:56:33+00:00 2026-06-14T03:56:33+00:00

I used the Fireworks init function to store a particle into the particles vector

  • 0

I used the Fireworks init function to store a particle into the particles vector class.
And when I try to retrieve the count of the particles vector in the update() function, the particles vector is empty. Why?

Fireworks.cpp class:

void Fireworks::init(){
    float x = randf();
    float y = - 1 * randf(); //Going UP
    float z = randf();

    Particle part(position,Vector3f(x,y,z), color, randInt(1,50));
    particles.push_back(part);
}

bool Fireworks::update(){
    Particle particle;
    int count = particles.size(); //Total num of particles in system
    cout << particles.size() << " ";
}

class Fireworks: public ParticleSystem {
private:
  void init();

public:

  Fireworks(Vector3f pos, Vector3f col) {
    position = pos;
    color = col;
    init();
  }

  virtual bool update();
};

particlesystem.h

class ParticleSystem {
protected:
  vector<Particle> particles;

public:
  //virtual Particle generateParticle();
  virtual bool update(){return false;};
};

main.cpp

ParticleSystem *PS;
int main( int argc, char *argv[] ) {
  PS = &Fireworks(Vector3f(0,0,0), Vector3f(200,0,255));
  glutIdleFunc(move);
}

void move()
{
   PS->update();       
}
  • 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-14T03:56:34+00:00Added an answer on June 14, 2026 at 3:56 am
    PS = &Fireworks(Vector3f(0,0,0), Vector3f(200,0,255));
    

    This introduces undefined behavior. The right hand side creates a temporary, which will be deleted as soon as that full expression is over (i.e. right after the ;). PS will point to a deleted object after that line – doing anything with it is undefined behavior.

    Use new.

    PS = new Fireworks(Vector3f(0,0,0), Vector3f(200,0,255));
    

    Also, you must return from all functions that are declared as returning something (non-void). It doesn’t matter if they’re virtual or not.

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

Sidebar

Related Questions

I used Attach method to update my Database name=New Name; checkBox1=false; Entity entity= new
I used SWIG for generating some native JNI function interface for Irrlicht C/C++ 3D
I used Netbeans IDE to compile and run the below program. public class Unicode
I used to use the anonymous self-execute function in js: ((function(){ //do something })();
I used to run the following code in Lion to open terminal, update a
I used to get all public vars from a class inside a class with
I used fireworks with netbeans to make php website. First i sliced my design
I used function which got IP address like below: public static final String IPV4_REGEX
Used to be quite happy with the Ctrl + Shift + F10 shortcut in
Used code I found on SO to use the COM based Acrobat Reader to

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.