Need help with class constructor..

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 23
Reputation: Undermine is an unknown quantity at this point 
Solved Threads: 2
Undermine Undermine is offline Offline
Newbie Poster

Need help with class constructor..

 
0
  #1
Nov 26th, 2008
HEADER..
#include <string>
using std::string;
class Blackjack
{
  public:    
           
        Blackjack(string);  
        void Shuffle();
        void Intro(string);
        void InitDeck(Card deck[],int numCards);
        void PrintCard(int);
      //  void Card(int);     
             
             
             
  private:
          
        int deck[52];  //deck of 52 cards.

};


BODY
#include    <iostream>
#include    <fstream>
#include    <cctype>
#include    <cstdlib>
#include    <ctime>
using namespace std;

     
const int       NUM_CARDS = 52;
enum            { Spades, Clubs, Hearts, Diamonds };
enum            { JACK = 11, QUEEN, KING, ACE };


// type definitions
typedef int         SuitType;
typedef int         RankType;
typedef int         ValueType;


// structure declarations
struct  Card
{
    SuitType    suit;
    RankType    rank;
    ValueType   value;
};

#include "bj.h"

Blackjack::Blackjack(string name)
{
    Intro( name );
                      
}
void Blackjack::Intro(string name)
{
cout<<"##############################################################"<<endl;    
cout<<"Program done by" <<  endl;
cout<<"Lets define the basic rules::" << endl;
cout<<"##############################################################"<<endl;
system("PAUSE");


void Blackjack::InitDeck(Card deck[] int numCards)//what each card is

{
    auto    int         deckIndex = 0;
    auto    RankType    rankCounter;
    auto    SuitType    suitCounter;

    for (suitCounter = Spades; suitCounter <= Diamonds; ++suitCounter)
        {
        for (rankCounter = 2; rankCounter <= ACE; ++rankCounter)
            {
            // set the suit and rank members
            deck[deckIndex].suit = suitCounter;
            deck[deckIndex].rank = rankCounter;

            // set the value member
            if (ACE == deck[deckIndex].rank)
                {
                // if we have an ace, assign the highest possible value
                deck[deckIndex].value = 11;
                }
            else if (deck[deckIndex].rank >= JACK)
                {
                // if we have a face card, assign it a value of ten
                deck[deckIndex].value = 10;
                }
            else
                {
                // the rank of the card is its value
                deck[deckIndex].value = deck[deckIndex].rank;
                }
            ++deckIndex;
            }
        }

}  // end of "InitDeck"

MAIN


#include<iostream>


#include "bj.h"


//-------------------------------------------------------------------

int main(int argc, char *argv[])
{ 
int numCards=0; //to know what card you are on
Blackjack myBlackjack("welcome to blackjack");

myBlackjack.Shuffle();
myBlackjack.PrintCard(0);
myBlackjack.InitDeck(deck[],52);

//myBlackjack.InitDeck();



system("\nPAUSE");

return 0;
}


//-------------------------------------------------------------------
Error:
prototype for `void Blackjack::InitDeck(Card*)' does not match any in class `Blackjack'
void Blackjack::InitDeck(Card*, int)

??
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Need help with class constructor..

 
0
  #2
Nov 26th, 2008
Missing ',' huh....
see this..
  1.  
  2. void Blackjack::InitDeck(Card deck[] int numCards)
  3. {
  4. //...
  5. }
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 23
Reputation: Undermine is an unknown quantity at this point 
Solved Threads: 2
Undermine Undermine is offline Offline
Newbie Poster

Re: Need help with class constructor..

 
0
  #3
Nov 26th, 2008
Ok i fixed that but now when i run main i get..

  1. #include<iostream>
  2.  
  3.  
  4. #include "bj.h"
  5.  
  6.  
  7. //-------------------------------------------------------------------
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11. int numCards=0; //to know what card you are on
  12. int deck[52];
  13. Blackjack myBlackjack("welcome to blackjack");
  14.  
  15. myBlackjack.Shuffle();
  16. myBlackjack.PrintCard(0);
  17. myBlackjack.InitDeck(deck[],52);
  18.  
  19. //myBlackjack.InitDeck();
  20.  
  21.  
  22.  
  23. system("\nPAUSE");
  24.  
  25. return 0;
  26. }

variable or field `InitDeck' declared void
'class Blackjack' has no member named 'InitDeck'

/facepalm
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC