Can anyone help me with my Blackjack C++ project?

Page 1 of 1 [ 4 posts ] 

hyperbolic
Veteran
Veteran

User avatar

Joined: 14 Aug 2006
Gender: Male
Posts: 1,869

10 Nov 2006, 11:58 pm

I started hobbyist programming in BASIC as a preteen and then C three-four years ago, in addition to several other languages along the way (Python, Scheme, PHP, VB). My programming experience until this college semester, even if the language I was programming in was technically object-oriented, has been in strictly in functional programming. But now I am in college and taking a C++ class, my first foray into the object oriented programming realm, and am having some difficulty with my current project, a card game (Blackjack), in which I will be passing around a bunch of strings to indicate the face of a card (there is a card class) and the status of the dealer class. My main problem? The function that I have defined to get the status of the dealer class, which is defined so that it returns a string variable is giving me the following compiler error:

Quote:
dealer.h(17) : error C2146: syntax error : missing ';' before identifier 'get_status'


Here is the class definition file:

Quote:
/* Dealer.h -- Dealer class header file ( specification ) */



class Dealer
{

public:



void play();
void hit();
void stay();
void quit();

string get_status();

private:

string status;
CardDeck card_deck;

};


Here is the class implementation file:

Quote:
/*
|----------------------------------------|
| MODULE NAME: Dealer.cpp |
| |
| ABSTRACT: class implementation |
| MACHINE/OS: |
| PROGRAM TYPE: |
| REVISIONS: |
| DESCRIPTION: Dealer class |
|----------------------------------------|
*/

#include "Dealer.h"


void Dealer::play()
{

return;
}

void Dealer::hit()
{

return;
}

void Dealer::stay()
{

return;
}

void Dealer::quit()
{

return;
}

void Dealer::get_status()
{

return;
}


Can anyone tell from the class files what I've left out or where I've made my mistake?

Thanks in advance.



pernicious_penguin
Pileated woodpecker
Pileated woodpecker

User avatar

Joined: 1 Sep 2005
Age: 54
Gender: Male
Posts: 183

12 Nov 2006, 4:22 am

the return type in the header is 'string'.. which requires you to do an include for either the STL or regular version of string

so either you need #include <string.h>
or
#include <string>
(after all includes...) using namespace::std;

Also: it may have to be either 'string your_data' or 'String your_data' (im coding in python right now, so I forgot, just try the 4 combos with the two headers)

-----
p.s. indent your code like in the definitions after a public/private block such as

public:
void this_is_a_fuc()

private:
char dude[50];
-----

post here if it does or doesn't work



hyperbolic
Veteran
Veteran

User avatar

Joined: 14 Aug 2006
Gender: Male
Posts: 1,869

12 Nov 2006, 1:40 pm

It eliminated many of the error messages (thanks--it's stuff like this that makes WP so awesome), but I am now receiving the following error:

Quote:
. . .Card.h(9): error C2011: 'Card' : 'class' type redefinition



hyperbolic
Veteran
Veteran

User avatar

Joined: 14 Aug 2006
Gender: Male
Posts: 1,869

12 Nov 2006, 2:51 pm

That problem is now fixed. I had to add an #ifndef preprocessor control structure around the class definition.

Now I'm on to actually creating the algorithms. (My favorite part.)