Function Call to a Class
Jul 26, 2011 at 11:46pm UTC
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 Jul 26, 2011 at 11:47pm UTC
Jul 26, 2011 at 11:53pm UTC
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 Jul 26, 2011 at 11:53pm UTC
Jul 27, 2011 at 12:26am UTC
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.