473,385 Members | 1,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Friend Class Blackjack and Bet

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
3 2655

"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
I did that too but it still doesnt work. Any other way...?

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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: cppaddict | last post by:
Hi, Is it possible that class A references class B, and class B references class A? Specifically, here is my problem. I have a card table class (Table), which represents a table at which...
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
9
by: Adam Badura | last post by:
I have code like this template<int size> big_int { /* ... */ template<int size2> friend class big_int<size2>; }; What I wanted to achive is to be able to easly convert different sized...
2
by: freegnu | last post by:
how to declare a friend function that can access two class it will look like the following class A { private: int i; public: A(){} ~A(){} friend void call(A &a, B &b);
6
by: gmarkowsky | last post by:
Hi all, I'm trying to import a class from a module. The class looks like this: class App: def __init__(self, master): frame = Frame(master) frame.pack()
28
by: =?iso-8859-1?q?Luis_M._Gonz=E1lez?= | last post by:
I've come across a code snippet in www.rubyclr.com where they show how easy it is to declare a class compared to equivalent code in c#. I wonder if there is any way to emulate this in Python. ...
5
by: Amit Gupta | last post by:
How do I do it (either by friend or by any other hack). I have three class, I am just writing derivation below: class A{} class B{} class C : public class B{} class D: public class B ()
6
by: gregpinero | last post by:
How do I add a decorator to a class method? Here's what I want to do, but I guess my syntax isn't right. Any advice? class A: def pre(self,fn): def new_func(*args,**kwargs): print 'hi'...
6
by: WaterWalk | last post by:
I find friend declaration just very tricky. I tried the following examples on both MingW(gcc 3.4.2) and VC++ 2005. The results are surprising. Example1: namespace ns1 { class Test { friend...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.