Function Call to a Class

I need a little help with the syntax of a function call.

1
2
3
4
5
6
int main() {
   Deck d1;
   Player p1;
   p1.get_card(d1);
...
}


1
2
3
4
5
class Player {
...
   void Player::get_card(std::list<my_namespace::Deck> *&my_deck)
   {...}
}


If it's not clear, I'm trying to pass d1 (which is a std::list) as a reference parameter so that I can change it within the Player class function.

Let me know if this doesn't make sense.

Thanks!
Last edited on
You're passing it as a reference to a pointer.

1
2
3
Player::get_card(std::list<my_namespace::Deck> *&my_deck)  // reference to a pointer (*&)
Player::get_card(std::list<my_namespace::Deck> *my_deck)  // pointer (*)
Player::get_card(std::list<my_namespace::Deck> &my_deck)  // reference (&) 


You want to pass it as a reference, so get rid of that *


EDIT:

also, are you passing a Deck? or a list of Decks?
Last edited on
Thank you. Good call on the list of Decks. I was making this too complicated. It compiles for now, so let's see if I can work with it the way I intend.

Thanks again!
Topic archived. No new replies allowed.