Friend Class Blackjack and Bet

S

slyphiad

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 ^_^
 
J

John Harrison

slyphiad said:
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
 
J

John Harrison

slyphiad said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top