Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Friend Class Blackjack and Bet

Reply
Thread Tools

Friend Class Blackjack and Bet

 
 
slyphiad
Guest
Posts: n/a
 
      10-13-2004
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 ^_^
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      10-13-2004

"slyphiad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
slyphiad
Guest
Posts: n/a
 
      10-15-2004
I did that too but it still doesnt work. Any other way...?

Thank you...^_^
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      10-15-2004

"slyphiad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
card-counting program for blackjack luser- -droog C Programming 1 02-08-2012 06:59 AM
[SUMMARY] Studying Blackjack (#151) Ruby Quiz Ruby 0 01-10-2008 05:18 PM
[QUIZ] Studying Blackjack (#151) Ruby Quiz Ruby 41 01-10-2008 03:36 AM
BlackJack on mobile phone using J2ME Qie Tao Java 1 08-08-2006 11:03 PM
Asymptopia BlackJack (written in Python) Charlie Cosse Python 0 07-29-2003 03:59 AM



Advertisments