This is the situation: a Player class with statistics as variables. a Keeper class derived from Player.
an Action class a Run class derived from Action
the player class has vector<Action*>
I don't understand how i can implement the following functionality: iterate through the vector and based on the action, update the correct attribute in Player or Keeper (numberOfRunKm and numberOfSaves)
class Action {
public:
Action();
virtual ~Action();
virtual void write();
};
class Run: public Action {
double runKm;
public:
Run(double runKm);
~Run();
double getRunKm() const;
void setRunKm(double runKm);
void write();
};
class Save: public Action {
public:
Save();
~Save();
void write();
};
class Player {
string name;
vector<Action*> actions;
double numberOfRunKm = 0.0;
public:
Player(const string &name);
~Player();
virtual void write();
void run();
void addAction(Action* action);
void updateStatistics();
};
class Keeper: public Player {
int numberOfSaves = 0;
public:
Keeper(const string &name);
~Keeper();
void write();
void save();
};