DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Need help with class constructor.. (http://www.daniweb.com/forums/thread159564.html)

Undermine Nov 26th, 2008 6:12 am
Need help with class constructor..
 
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)

??

cikara21 Nov 26th, 2008 6:18 am
Re: Need help with class constructor..
 
Missing ',' huh....
see this..

void Blackjack::InitDeck(Card deck[] int numCards)
{
    //...
}

Undermine Nov 26th, 2008 7:07 am
Re: Need help with class constructor..
 
Ok i fixed that but now when i run main i get..

#include<iostream>


#include "bj.h"


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

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

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

//myBlackjack.InitDeck();



system("\nPAUSE");

return 0;
}

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

/facepalm


All times are GMT -4. The time now is 9:34 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC