passing variables located within pointer-type classes

Hoping some awesome C++ guru can help me out.

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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);
Last edited on
function1(Player1->hand[k],&Player1->hand,1,0); Maybe?


Haha. I wish :) I think that the &Player1->hand is wrong too, not just the *(Player1->hand)[k]
Post Edited...
I actually just got the compiler to get past that point using:

function1(&*(Player1->hand)[k],Player1->hand,1,0);

It might explode later though, we'll see. Seems nonsensical.
Topic archived. No new replies allowed.