i am dealing with a c++ school project. i want to store child card object inside parent card object in main function because i need to set card inside the library (std::vector<card> _library;
) as same type.
what i need to use in main function to store child classes inside parent classes?
definition of classes and main function :
#ifndef CARD_H
#define CARD_H
class player;
class card
{
protected:
std::string _name;
std::string _type;
player _owner;
public:
card();
card(std::string name, std::string type);
void setOwner(player&);
virtual void play();
};
#endif
#ifndef ENCHANTMENT_H
#define ENCHANTMENT_H
class enchantment :public card
{
public:
enchantment()
enchantment(std::string name, std::string type);
void play() override;
};
#ifndef CREATURE_H
#define CREATURE_H
class creature :public card
{
public:
creature();
creature(std::string name, std::string type);
void play()override;
};
#endif
#ifndef PLAYER_H
#define PLAYER_H
class card;
class player
{
protected:
std::string _name;
std::vector<card> _hand;
std::vector<card> _library;
std::vector<card> _in_play;
std::vector<card> _discards;
public:
player();
player(std::string name);
//setter functions
void setLibrary(std::vector<card>);
};
#endif // !PLAYER_H
int main() {
player p1("player1");
creature p1Soldier01("Soldier", "Creature");
creature p1Soldier02("Soldier", "Creature");
enchantment p1Rage01("Rage", "Enchantment");
enchantment p1Rage01("Rage", "Enchantment");
std::vector<card> player1Cards(4);
//this is the part i need help.
p1.setLibrary(player1Cards);
}