954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Accessing functions from base class

Blackjack class is derived from card class ( see attached playingcard.h and blackjack.h)
I have problem with:
void blackjack::DealCards() 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???

Attachments playingcards.cpp (7.78KB) playingcards.h (0.67KB) blackjack.h (0.41KB)
dirs
Newbie Poster
3 posts since May 2004
Reputation Points: 10
Solved Threads: 0
 

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!!

BlackDice
Light Poster
43 posts since Apr 2004
Reputation Points: 19
Solved Threads: 0
 
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!

dirs
Newbie Poster
3 posts since May 2004
Reputation Points: 10
Solved Threads: 0
 

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:

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!

BlackDice
Light Poster
43 posts since Apr 2004
Reputation Points: 19
Solved Threads: 0
 
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!

dirs
Newbie Poster
3 posts since May 2004
Reputation Points: 10
Solved Threads: 0
 

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

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!
BlackDice
Light Poster
43 posts since Apr 2004
Reputation Points: 19
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You