I am having trouble finding the method to store instances of similar classes into a vector. I thought about using a base class, but I am not sure whether it will work. For example, using sports:
class player //base
{
std::string name;
int age;
player(std::string name, int age) name (name), age (age);
};
class soccerplayer: public player
{
float goal_per_game;
//etc
};
class basketballplayer: public player
{
float defensive_blocks;
float three_pointers_per_game;
//etc
};
class hockeyplayer: public player
{
//etc
};
std::vector<player> favoriteplayers;
favoriteplayers.push_back(player("Lionel Messi", 33));
I am not sure if there is a method to store the various instances of this class. If not, what workaround is possible?