A problem with passing.

This is a discussion on A problem with passing. within the C++ Programming forums, part of the General Programming Boards category; I have run into a small snag in a blackjack program I'm making. I used to know the answer but ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    2

    A problem with passing.

    I have run into a small snag in a blackjack program I'm making. I used to know the answer but a 2 year leave of programming absence has left me bereft of the answer.

    I send a vector to a deal function (whose code I will include below) in the function it appears as though the vetor is properly filled, but upon leaving the function, it erm, loses all of it's new memory except in the first cell. Any ideas

    here's the delenquint function

    void Deck::deal(vector<card> &hand, int num)
    {
    hand.resize(num);

    int size = hand.size();
    card hold;

    int s, f;
    for(int i=0; i<num; i++)
    {
    s= rand()%4;
    f= rand()%12+1;


    while(used[s][f] > decknum)
    {
    s= rand()%4;
    f= rand()%12+1;
    }
    hand[i].face = f;
    hand[i].suit = s;
    hold = hand[i];
    }
    }

  2. #2
    Shadow12345
    Guest
    show me how you are passing it in when you call that method

    I don't think there is anything wrong with what you have showed, but I haven't done extensive work with passing vectors by reference (like 4 days worth actually)

    like i said im not too sure what is wrong but no one else has replied. i think the problem could be due to the fact that you are potentially creating new card objects (or deleteing them, depending on the value of num and how many cards you previously had) but you may not be initializing the cards correctly. i.e you didn't provide anything in the constructor for the card class/struct and then when you go to access those cards and blamo it is uninitialized jibberish. if i am way off you can tell me to die.
    Last edited by Shadow12345; 12-06-2002 at 02:29 PM.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I'm with Shadow12345 on this one. And Bartleby I'm assuming you aren't aware of code tags. Just type [ code] before your code and [/code] after. Unless of course you want to see kermi's code tag reply, in which case you've done the right thing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-11-2008, 02:42 AM
  2. Replies: 1
    Last Post: 03-31-2008, 05:53 PM
  3. Problem with passing structs to a function.
    By darsh1120 in forum C Programming
    Replies: 7
    Last Post: 03-11-2008, 04:36 AM
  4. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  5. problem with passing data, again.
    By vnrabbit in forum C Programming
    Replies: 3
    Last Post: 10-22-2002, 02:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21