I've had many problems understanding pointer variables in the past, and it seems to be catching up
to me. I'm trying to make a fairly simple card game program, and I know it will be faster to seek help instead of try to randomly input *'s and &'s on my own.
My problem is that I'm trying to pass a pointer to a class into a function, and then within that function I am trying to pass regular variables from that class (not pointers) into another function. Here's the essential code:
class Card
{
public:
char suit;
char name;
};
class Player
{
public:
int money;
vector<Card *> hand;
Player( int mo = 0, vector<Card *> han = new vector<Card *>)
{
money = mo;
hand = han;
}
void draw_card();
};
void function1(Card *card_assigning_to, vector<Card *> your_hand,
int card_position_in_hand,
int debug_detail);
void function2(Player *Player1,
Player *Player2,
int debug_level)
{
for(int k=0; k<Player1->hand.size(); k++)
{
function1(*(Player1->hand)[k], //yes, these are completely wrong
&Player1->hand,
1,
0);
}
}
int main(int argc, char *argv[])
{
//stuff up here not worth noting
Player Player1, Player2;
vector(Player *> Players;
Players.push_back(&Player1);
Players.push_back(&Player2);
function2(Players[0], Players[1], 0);
}
There are probably code errors above, since this isn't the EXACT code in the program. But the basic problem is there: how do I represent Player 1's hand and card in hand when passing them into function1? Thanks to those who contribute :)
function1(Player1->hand[k],Player1->hand,1,0);
Edit: Maybe your vector<Card*> is a vector<Card*>*. In case: function1((*(Player1->hand))[k],Player1->hand,1,0);