Compiler: Microsoft Visual Studio 2008
Language: C++
OS: Windows XP
Hi, Im creating a Black Jack game and trying to use an overloaded constructor. I want to be able to create the House hand, player 1 hand, player 2 hand, and deck as a list of cards, but want to use an overloaded constructor thats used by the deck to generate the list of 52 cards, and just use the default constructor for the actual hands. When I attempt this though, Im given the followig compilation error:
.
.
1>c:\documents and settings\...\CardGame.h(49) : error C2059: syntax error : 'constant'
1>c:\documents and settings\...\CardGame.h(49) : error C2059: syntax error : 'constant'
.
.
1>BlackJack - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Im guessing im overloading the CCardList constructor the wrong way, or the compiler doesnt like overloaded constructors being accessed by other classes, or im just forgeting something silly. I can remove the CGame class and just declare the CCardlist deck, house, p1Hand, and p2Hand in the main() function and the overloaded CCardList(bool isDeck) method works fine. Any help or suggestions to do this a different way would be appreciated.
File name: CardGame.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
class CCard
{
private: int c_value;
int c_suit;
public: CCard();
};
struct cardNode
{
CCard data;
cardNode *next;
};
typedef cardNode *cardPtr;
class CCardList
{
private: cardPtr cl_head;
void createDeck();
public: CCardList();
CCardList(bool isDeck);
~CCardList();
};
class CGame
{
private: CCardList g_deck(true);
CCardList g_house;
CCardList g_hand1;
CCardList g_Hand2;
public: CGame();
};
|
File Name: CardGame.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include "CardGame.h"
using namespace std;
CCard::CCard()
{
cout << "CCard();" << endl;
}
CCardList::CCardList()
{
cl_head = NULL;
cout << "CCardList()" << endl;
}
CardList::CCardList(bool isDeck)
{
cl_head = NULL;
generateDeck();
cout << "CCardList(bool isDeck)" << endl;
}
CCardList::~CCardList()
{
cout << "~CCardList()" << endl;
}
CGame::CGame()
{
cout << "CGame();" << endl;
}
|
File Name: CardGameApp.cpp
1 2 3 4 5 6 7 8 9 10
|
#include <iostream>
#include "CardGame.h"
using namespace std;
int main()
{
CGame BlackJack;
return 0;
}
|