I've seen that similar question have been asked but it couldn't help with the problem I'm having. Since it's a bit big code, to keep post short, I'll post only things I find necessary but if you need more info, feel free to ask for more code. So, I'm trying to make a simple card game. I have this class Player with this constructor and couple of attributes.
class Player
{
public:
Player(std::string playerName_, int lifeEnergy_, int magicEnergy_, CardCollection* deck_) : playerName(playerName_), lifeEnergy(lifeEnergy_), magicEnergy(magicEnergy_), deck(deck_) { activatedCards = hand = destroyedCards = nullptr; }
private:
std::string playerName;
int lifeEnergy;
int magicEnergy;
CardCollection* deck, *hand, *activatedCards, *destroyedCards;
};
And in my main.cpp I've created deck, inserted a couple of cards and after I've tried creating object of class Player and pass the following parameters:
Player p2("Name", 4000, 200, deck1);
However, Visual Studio is posting a message that "no instance of constructor Player::Player matches the argument list argument types are const char[5], int, int, CardCollection. So this "Name" is underlined, giving me an error.
What am I doing wrong? I mean, first parameter of constructor is std::string, I'm passing string in main, why does it display this error?
edit:
CardCollection has these private attributes:
private:
struct Elem
{
Card* card;
Elem* next;
Elem(Card* card_) : card(card_), next;(nullptr) {}
~Elem() { delete card; }
};
Elem* first, *last;
int totalCardNum;
Now, Card can't be copied (that was specified) so I deleted copy and move constructors. Since Card is part of CardCollection, I coulnd't use copy and move constructor there as well so I used pointers.
So I changed main.cpp that it matches with that constructor with pointer. This is how I created card:
Wizard* c1 = new Wizard("Wizard 1", 2, 500); // never mind the parameters, it's some card stats. This part totally works
So I did this after:
CardCollection* deck1;
deck1->addIntoCollection(c1);
Then I had error that deck1 is uninitialised. And this is the moment I lost myself totally in this. I don't know what to do at this point.
possible way out: Before I had Player, both cards and deck worked perfectly as I tested printing elements of the list and it had all cards there. Since that was last best working state, is there a way to implement Player with this all in mind?