Hi all, I have a simple C++ OOP question regarding a problem I've run into.
I have a Particle class, and ParticleManager class which handles a list of Particles. Then I want to extend these two classes for different types of particles (e.g. Ball and BallManager).
My problem is when I call BallManager balls.update(); it doesn't seem to run the Ball::update function but only the Particle::update();
class Ball : public Particle {
friendclass BallManager;
protected:
...some more vars and functions
void update();
public:
Ball(...);
};
class BallManager : public ParticleManager {
public:
~BallManager();
void update();
void add(...);
};
Ball::Ball(...) : Particle(...) {
... custom init code
}
void Ball::update() {
printf("Ball update \n");
.... custom ball update WHICH IS NOT BEING CALLED
}
BallManager::~BallManager() {
}
void BallManager::add(...) {
ParticleManager::add(...);
... custom add code
}
void BallManager::update() {
ParticleManager::update();
... custom manager code which is being called
}
maybe its because i'm a bit tired but I can't see what I need to do for the ParticleManager::update() inside BallManager::update() to loop through all the particles but treat them as Balls instead of Particles...