Here is what I'm trying to do:
Create a Vector of a parent class, and fill it up with different children of that class, then make a loop which cicles through the vector and calls a method from each class. The problem is that even if the child class has overriden the method, it keeps calling the parent's method. The method is declared as virtual in both the parent and the child class isn't that how it should be?
I'm absolutely sure the method has the same signature: return type, name and parameters (in this case none), this is correct, right?
Here is the section I'm having trouble with
Code:
void CSDL::render(std::vector<Entity> entities)
{
Uint32 color;
color = SDL_MapRGB(m_screen->format, 0, 0, 0);
SDL_FillRect(m_screen, NULL, color);
for (int i = 0; i < entities.size(); i++)
{
drawSprite(entities[i].getX(), entities[i].getY(),
entities[i].getSprite());
entities[i].update(); // <--- This is the method it should call from the child class, but is calling from the parent.
}
SDL_Flip(m_screen);
}