Page 1 of 1 [ 10 posts ] 

hyperbolic
Veteran
Veteran

User avatar

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

11 Nov 2006, 12:14 am

I have quoted my post in the school forum:

xon wrote:
. . .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 |
| AUTHOR: Matthew Martin |
| 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.



PenitentSpark
Raven
Raven

User avatar

Joined: 17 Jun 2006
Age: 43
Gender: Male
Posts: 122
Location: on the internet

11 Nov 2006, 2:49 am

Don't certain C++ compilers need you to include some file, like "strings.h", to know how to use strings?



hyperbolic
Veteran
Veteran

User avatar

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

11 Nov 2006, 3:59 am

Quote:
Don't certain C++ compilers need you to include some file, like "strings.h", to know how to use strings?


Yes. All C++ compilers, actually.

I did an "#include <string>" in my main.cpp module. I tried this in both the Dealer class definition and the Dealer class implementation; however, it did not solve my problem. Should I have done this elsewhere or differently?



hyperbolic
Veteran
Veteran

User avatar

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

11 Nov 2006, 10:32 am

I just found the following class online and I noticed something in it that I might have been forgetting that the C++ language required:

Quote:
class CRectangle {
int width, height;
public:
CRectangle ();
CRectangle (int,int);
int area (void) {return (width*height);}
};


Notice that the int area function is defined in the class with a void in the argument list. Is this required? I think that this could be the source of my problem, but I am unable to test my code here at work.



TheMachine1
Veteran
Veteran

User avatar

Joined: 11 Jun 2006
Gender: Male
Posts: 8,011
Location: 9099 will be my last post...what the hell 9011 will be.

11 Nov 2006, 11:31 am

string get_status();

I'm guessing the compiler does not know what "string" type is.

I know very little about c++. My wild guess is

string.get_status(); may work :D

If I remeber I will ask my IT genious brother-in-law and sister about it.
------------

A quick scan of my c++ book I do not see string used as a type class. They use char
in the book.



hyperbolic
Veteran
Veteran

User avatar

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

11 Nov 2006, 12:11 pm

Quote:
A quick scan of my c++ book I do not see string used as a type class. They use char
in the book.


Until recently, compiler support for a built-in string class was nebulous at best. However, my teacher uses a string class and it appears to be present in the Visual C++ compiler, as I have used it for other programs that I have written in C++ using functional programming style.

Quote:
If I remeber I will ask my IT genious brother-in-law and sister about it.


That would be very cool. Thanks in advance. :D



TheMachine1
Veteran
Veteran

User avatar

Joined: 11 Jun 2006
Gender: Male
Posts: 8,011
Location: 9099 will be my last post...what the hell 9011 will be.

11 Nov 2006, 10:16 pm

Hmm you should not of thank me because I forgot to ask :cry:

If you comment out the line string get_status();

or change it to void get_status(); will it compile?



neurodeviant
Veteran
Veteran

User avatar

Joined: 14 Oct 2006
Age: 40
Gender: Male
Posts: 1,182
Location: Britland

12 Nov 2006, 12:45 pm

I'm quite new to C++, but shouldn't the last lines of the cpp file be:

Code:
string Dealer::get_status()
{

return;
}



hyperbolic
Veteran
Veteran

User avatar

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

12 Nov 2006, 1:24 pm

Thanks for catching that.



hyperbolic
Veteran
Veteran

User avatar

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

14 Nov 2006, 1:11 am

This project was due on the 13th. After that, there is a 10 point deduction for being late

I was working right up until 11:59, coding and then trying to make the zip archive and e-mail it.

Luckily, I sent the e-mail at 11:59. :D

As for the Blackjack game itself, most of the time it works. There are a few bugs here and there, but nothing too major that the teacher would count off on if I am lucky. Still, I hope the teacher does not encounter these bugs, which can occur fairly at random since the program uses a random number generator.

Unlike my previous programming projects, the code I wrote for this project seemed somewhat disorganized. Technically it should work, and the bugs I mentioned would probably be something that could be fixed my hacking and creating workarounds, but I do feel that if I had perhaps planned my source code a bit better the code might have seemed more organized to me. In my experience, more organized code means fewer bugs, too. :)