So today I started playing around with polymorphism and I am making a pretty basic game using the principles of it. I have 5 different obstacles that inherit from the ObstacleClass and then in my main cpp file I have a vector of obstacle pointers pointing at the various different types that appear within the game
1 2
Obstacles *newObstacle = new blockDrop
Obst.push_back(newObstacle);
that as just an example of how I'm adding obstacles to the vector, with the example for a dropping block obstacle
at one point in the games loop though there is a function that I wish to access from only one type of obstacle, so I can no longer loop through the 'Obst' vector and call that function for all of them as it doesn't exist for the majority of them. Is there a way to separate the vector based on what each element is pointing at so that I can just access that function for that one child class when necessary?
I would say that defeats the point of having pointers to general Obstacle objects; if you can't treat all the objects as mere Obstacles and have the game function, what was the point in having the class hierarchy?
The majority of the stuff that each obstacle inherits is the same though, there is just one obstacle that has a bit of extra functionality, but I am having trouble calling that extra functionality from a vector of obstacle pointers. I seemed to be under the impression that polymorphism would allow me to do this but maybe I am doing something wrong
edit: nvm I was being stupid and forgot to add the function to the cpp file of the Obstacle class so that it can be called when referring to any obstacles that don't need the special functionality