By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,928 Members | 1,810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,928 IT Pros & Developers. It's quick & easy.

Friend Class Blackjack and Bet

P: n/a
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 ^_^
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"slyphiad" <sl******@gmail.com> wrote in message
news:a5**************************@posting.google.c om...
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
Jul 22 '05 #2

P: n/a
I did that too but it still doesnt work. Any other way...?

Thank you...^_^
Jul 22 '05 #3

P: n/a

"slyphiad" <sl******@gmail.com> wrote in message
news:a5**************************@posting.google.c om...
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
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.