Friend Class Blackjack and Bet

Discussion in 'C++' started by slyphiad, Oct 13, 2004.

  1. slyphiad

    slyphiad Guest

    Here's the problem that i got...

    I'm trying to create a blackjack game. Here, I'm trying to create 2
    blackjack games. A game with bet and without bet. So basically what i
    did, was create 2 class: a blackjack class and a bet class.

    How can i access the bet class from the blackjack class?
    I tried using the code below in one of the function in blackjack.

    Bet betgame;
    betgame.startBet();

    However, if i do it this way, it will only be available on that
    function only. is there a way so that the bet class is available to be
    accessed by all functions in blackjack.

    Do I have to use "friend" here? Would it solve my problem?

    Also, just wondering if there's a way to retain a value in a function.
    So the next time, i use the function again. It will still retain the
    value from the use of last function. I heard that there's a keyword to
    do this but cant find it anywhere.

    Can anyone help me with this problem? Thanks so much ^_^
     
    slyphiad, Oct 13, 2004
    #1
    1. Advertising

  2. "slyphiad" <> wrote in message
    news:...
    > Here's the problem that i got...
    >
    > I'm trying to create a blackjack game. Here, I'm trying to create 2
    > blackjack games. A game with bet and without bet. So basically what i
    > did, was create 2 class: a blackjack class and a bet class.
    >
    > How can i access the bet class from the blackjack class?
    > I tried using the code below in one of the function in blackjack.
    >
    > Bet betgame;
    > betgame.startBet();
    >
    > However, if i do it this way, it will only be available on that
    > function only. is there a way so that the bet class is available to be
    > accessed by all functions in blackjack.
    >
    > Do I have to use "friend" here? Would it solve my problem?


    No.

    >
    > Also, just wondering if there's a way to retain a value in a function.
    > So the next time, i use the function again. It will still retain the
    > value from the use of last function. I heard that there's a keyword to
    > do this but cant find it anywhere.


    The keyword is static but that isn't the answer here.

    >
    > Can anyone help me with this problem? Thanks so much ^_^


    The answer is to make betgame a member variable of Blackjack

    class Blackjack
    {
    public:
    ...
    private:
    Bet betgame;
    };

    Now every non-static method of Blackjack has access to a shared betgame
    variable.

    john
     
    John Harrison, Oct 13, 2004
    #2
    1. Advertising

  3. slyphiad

    slyphiad Guest

    I did that too but it still doesnt work. Any other way...?

    Thank you...^_^
     
    slyphiad, Oct 15, 2004
    #3
  4. "slyphiad" <> wrote in message
    news:...
    >I did that too but it still doesnt work. Any other way...?
    >
    > Thank you...^_^


    That is the way, if you tried it and it didn't work that is because you
    didn't do it properly. Why not post the code?

    john
     
    John Harrison, Oct 15, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charlie Cosse

    Asymptopia BlackJack (written in Python)

    Charlie Cosse, Jul 29, 2003, in forum: Python
    Replies:
    0
    Views:
    393
    Charlie Cosse
    Jul 29, 2003
  2. Qie Tao
    Replies:
    1
    Views:
    705
    Luke Webber
    Aug 9, 2006
  3. Ruby Quiz

    [QUIZ] Studying Blackjack (#151)

    Ruby Quiz, Jan 4, 2008, in forum: Ruby
    Replies:
    41
    Views:
    435
    James Gray
    Jan 10, 2008
  4. Ruby Quiz
    Replies:
    0
    Views:
    94
    Ruby Quiz
    Jan 10, 2008
  5. Peter
    Replies:
    2
    Views:
    287
    Öö Tiib
    Jun 6, 2013
Loading...

Share This Page