I have classes Deck, abstract class Card and Spell and Minion which are both derived from Class. I have vector<unique_ptr<Card> >
of all existing Cards and now I want to place them into Decks. I want to use void Deck::addCard(<unique_ptr<Card>)
overloads for Minion and Spell.
I've tried changing the arguments and parameters to "dumb" * pointer, or just Card (which can't work, I know), references, non-references etc...
Calling addCard
Deck tmp;
for( const auto & it : mAllCards )
{
cout << typeid( *it ).name() << endl;
tmp.addCard( it );
}
addCard functions
void Deck::addCard( const unique_ptr<Card> & card )
{
cout << "basic" << endl;
}
void Deck::addCard( const unique_ptr<Minion> & minion )
{
cout << "minion" << endl;
}
void Deck::addCard( const unique_ptr<Spell> & spell )
{
cout << "spell" << endl;
}
The problem is that the Card version is called everytime, not the variants for derived types. Althrough typeid says Minion or Spell, not Card.