vendredi 25 septembre 2015

Dynamically generate new class objects from different classes

I'm currently writing a simulator for a card game. I'm trying to code a move generator. I have got a base class "Card" from which I'm deriving every card (around 150 different ones). They are pretty specific so I can't implement them within a single class (and I don't want to use any scripting language).

What I need (want) to do: Code 150 classes derived from "Card". Now I need to generate new objects during runtime and push them into my board.

For example:

std::vector<Card*> board;
board.push_back(new Card132());

So how would I be able to do this - cause I need to decide during runtime which object (from which class) I need to generate?

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire