943,549 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4026
  • C RSS
May 4th, 2004
0

Accessing functions from base class

Expand Post »
Blackjack class is derived from card class ( see attached playingcard.h and blackjack.h)
I have problem with:
void blackjack:ealCards() function.
I want to use function deal_hands from card class to set the value of pcard1 pcard2, dcard1 and dcard2.
How could I do that???
Attached Files
File Type: cpp playingcards.cpp (7.8 KB, 44 views)
File Type: h playingcards.h (683 Bytes, 34 views)
File Type: h blackjack.h (417 Bytes, 32 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dirs is offline Offline
3 posts
since May 2004
May 4th, 2004
0

Re: Accessing functions from base class

You should be able to just type in CPlayingCard::deal_hands() (if CPlayingCard is the name of your base class), and that should be all there is to it!!
Reputation Points: 19
Solved Threads: 0
Light Poster
BlackDice is offline Offline
43 posts
since Apr 2004
May 5th, 2004
0

Re: Accessing functions from base class

Quote originally posted by bdiamond ...
You should be able to just type in CPlayingCard::deal_hands() (if CPlayingCard is the name of your base class), and that should be all there is to it!!
Thanks for the reply!
The problem is that deal_hands function doesnt return anything at the moment.
Could it return an array of cards that could be used in the derrived class to set pcard1 , pcard2 etc.?
Thanks!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dirs is offline Offline
3 posts
since May 2004
May 5th, 2004
0

Re: Accessing functions from base class

if there's an array for it in the base class, you should be able to access that array the same way CPlayingCard::array[1] (or whichever element you're looking for). Or you could have it return an array of cards by declaring the function return type as CCard*. Then just return the name of the array from the function as that will be a pointer to the first address, and a count of the cards, if it's possible for it to change. then you can iterate through each one as you need to up until the count returned. Hope this helps!!:mrgreen:

Quote originally posted by dirs ...
Thanks for the reply!
The problem is that deal_hands function doesnt return anything at the moment.
Could it return an array of cards that could be used in the derrived class to set pcard1 , pcard2 etc.?
Thanks!
Reputation Points: 19
Solved Threads: 0
Light Poster
BlackDice is offline Offline
43 posts
since Apr 2004
May 6th, 2004
0

Re: Accessing functions from base class

Quote originally posted by bdiamond ...
if there's an array for it in the base class, you should be able to access that array the same way CPlayingCard::array[1] (or whichever element you're looking for). Or you could have it return an array of cards by declaring the function return type as CCard*. Then just return the name of the array from the function as that will be a pointer to the first address, and a count of the cards, if it's possible for it to change. then you can iterate through each one as you need to up until the count returned. Hope this helps!!:mrgreen:
I have tried to do like this CPlayingCard::array[1] but i get error
C:\cardgame\playingcards.cpp(154) : error C2275: 'blackjack::card' : illegal use of this type as an expression.
Thanks for reply!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dirs is offline Offline
3 posts
since May 2004
May 6th, 2004
0

Re: Accessing functions from base class

well try sending a pointer back of whatever type the array is then reference that pointer by a subscript



Quote originally posted by dirs ...
I have tried to do like this CPlayingCard::array[1] but i get error
C:\cardgame\playingcards.cpp(154) : error C2275: 'blackjack::card' : illegal use of this type as an expression.
Thanks for reply!
Reputation Points: 19
Solved Threads: 0
Light Poster
BlackDice is offline Offline
43 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Image Handler
Next Thread in C Forum Timeline: Possibility of mini servers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC