How can I reach my subclass? C++ -


in following code can't reach subclass. have have subclass underneath superclass inherit it, superclass won't know point unless subclass defined before it.

class particlesystem {     particle *ptr_to_particles;      void update()     {  // loop through number of particles        // , call update method.       ptr_to_particles[i].update();     } }  class particle : public particlesystem      //inherits particlesystem {     void update(); } 

or if can offer suggestions how differently, welcome it. thanks.

i think should reconsider design. particlesystem should have number of particle (e.g. std::vector<particle>). doesn't seem correct particle be type of particlesystem. this

class particle { public:     void update(); };  class particlesystem { public:     void update()     {         (auto particle : _particles)         {             particle->update();         }     }  private:     std::vector<particle*> _particles; }; 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -