Inheritance problem

I am building a app that consists of 20 mini games. Each one will inherit from the base class ‘game’ and have some common functionality. I am trying to store all games in a vector so I can access them with games[currentIndex]

In ofApp.h I have

vector<game*> games;

In ofApp.cpp

games.push_back(new gameHula());
games.push_back(new gameSkate());
...

for (int i = 0; i < 20; i++) {
	games[i]->setup();
}

game.h

class game{

public:

void setup();
void update();
void draw();

gameSkate.h

class gameSkate : public game{

public:

void setup();
void update();
void draw();

The problem is that when setup is called it only runs on the base class and not on gameHula or gameSkate. How can I make it so the child class setup is called first followed by the parent?

the virtual keyword can help you here:

http://en.cppreference.com/w/cpp/language/virtual

if you say virtual void setup() in the game object, it will help the derived object override the function. Since it’s overridden, you need to call the parent function, by saying:

game::update();

from within the derived function, ie:

gameSkate::update(){

 // do some game skate specific stuff: 
  ;
 // do some game specific stuff: 
 game::update();

}

hope that helps

Works perfectly, thanks @zach!