By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,589 Members | 1,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,589 IT Pros & Developers. It's quick & easy.

Help me, Obi C Kenobi...

P: n/a
You're my only hope!

OK, I gots a mystery on my hands. I'm hoping someone can tell me just
what the **** is going on here.

I'm familiar with other object oriented programming tools, such as Java
& REBOL. In an effort to become more familiar with C++, I decided to
write an object oriented BlackJack program. After writing some static
routines for Faces and Suits, I turned my attention to creating Cards
and Hands. Cards were no problem, Hands are starting to tick me off. :)

First, my header file for Hands:
================================================== ====================
#ifndef _Hand_H_
#define _Hand_H_

#include "Card.h"

class Hand {
public:
Hand();

bool add(Card prmCard);
bool canDouble();
bool canSplit();
int getSize();
int getValue();
bool isBlackjack();
bool isBusted();
bool isSoft();
void setHidden(int prmHideNo);
string toString();
string toString(bool prmLong);

private:
bool clsSoft;
int clsCount;
int clsHidden;
Card clsCards[0];
}
#endif //_Hand_H_
================================================== ====================

Next, my C++ file for Hands:
================================================== ====================
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

// Declarations...
#include "Hand.h"

// Definitions...
int clsCount;
int clsHidden;
bool clsSoft;
Card clsCards[0];

// Constructors...
Hand::Hand( ) {

}

// Methods...
.... All methods are currently stubs.
================================================== ====================

Please notice the "definitions" section. When compiled, it produces the
following error: "extraneous `int' ignored."

When I remove all definitions in that section, I get:
----------------------------------------------------------------------
12 Hand.cpp new types may not be defined in a return type
12 Hand.cpp return type specification for constructor invalid
----------------------------------------------------------------------

But when I change the definition section to remove the first, and only
first, int declaration, so that it looks like this:
================================================== ====================
// Definitions...
clsCount;
int clsHidden;
bool clsSoft;
Card clsCards[0];
================================================== ====================

It compiles successfully!

AND! More entertainingly! If I switch the declarations around so that
the bool is first, like this:
================================================== ====================
// Definitions...
bool clsSoft;
int clsCount;
int clsHidden;
Card clsCards[0];
================================================== ====================

I get the error: "'bool' is now a keyword." But, once again, like int,
leaving the bool keyword out compiles successfully.

What's going on?

I'm a C++ newbie, and I'm probably making some kinda C++ newbie mistake,
but because I a newbie, I've got no idea what that mistake might be.

I'm using DevCpp to compile this. Clues welcome.

Ed.
Jan 28 '07 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Ed Dana wrote:
You're my only hope!

OK, I gots a mystery on my hands. I'm hoping someone can tell me just
what the **** is going on here.
Posting incomplete code doesn't help your cause, you should distil the
problem down to something that can compile and exhibits your problem.
But...
>
// Definitions...
int clsCount;
int clsHidden;
bool clsSoft;
Card clsCards[0];
In what context are these? They appear to duplicate your class members.

--
Ian Collins.
Jan 28 '07 #2

P: n/a

[For some reason the google reply command isn't quoting correctly, so
I'm having to edit in exactly the spot I am trying to highlight, but
hopefully what I quote will be the same as what you actually
posted...]

On 28 Jan, 21:21, Ed Dana <EDan...@Cox.netwrote:
You're my only hope!

OK, I gots a mystery on my hands. I'm hoping someone can tell me just
what the **** is going on here.

I'm familiar with other object oriented programming tools, such as Java
& REBOL. In an effort to become more familiar with C++, I decided to
write an object oriented BlackJack program. After writing some static
routines for Faces and Suits, I turned my attention to creating Cards
and Hands. Cards were no problem, Hands are starting to tick me off. :)

First, my header file for Hands:
================================================== ====================
#ifndef _Hand_H_
#define _Hand_H_

#include "Card.h"

class Hand {
public:
Hand();

bool add(Card prmCard);
bool canDouble();
bool canSplit();
int getSize();
int getValue();
bool isBlackjack();
bool isBusted();
bool isSoft();
void setHidden(int prmHideNo);
string toString();
string toString(bool prmLong);

private:
bool clsSoft;
int clsCount;
int clsHidden;
Card clsCards[0];
}
Here's your real problem. You need a semi-colon here, and you haven't
put one in.
#endif //_Hand_H_
================================================== ====================

Next, my C++ file for Hands:
================================================== ====================
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

// Declarations...
#include "Hand.h"
So when the compiler gets here, it is expecting you to give the name
the the "Hand" that it thinks you are declaring. Hence the funny
results.
// Definitions...
int clsCount;
int clsHidden;
bool clsSoft;
Card clsCards[0];

Jan 28 '07 #3

P: n/a
Ed Dana schrieb:
You're my only hope!

OK, I gots a mystery on my hands. I'm hoping someone can tell me just
what the **** is going on here.
[...]
First, my header file for Hands:
================================================== ====================
#ifndef _Hand_H_
#define _Hand_H_

#include "Card.h"

class Hand {
[...]
Card clsCards[0];
An array can't be zero sized. Do you want a dynamic array? Then use
std::vector.
}
Semicolon?
#endif //_Hand_H_
================================================== ====================

Next, my C++ file for Hands:
================================================== ====================
[...]
// Declarations...
#include "Hand.h"

// Definitions...
int clsCount;
int clsHidden;
bool clsSoft;
Card clsCards[0];
What are these for?

You don't have to define class member variables unless they are static.
Then, you have to prefix them with the class name like so:

int Hand::clsCount;

But they aren't static...

[...description of some errors...]
What's going on?
Its the missing semicolon after the class Hand definition.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Jan 28 '07 #4

P: n/a
Ed Dana wrote:
I'm a C++ newbie, and I'm probably making some kinda C++ newbie mistake,
but because I a newbie, I've got no idea what that mistake might be.
The mistake is that the declaration of a class must be terminated with a
semicolon. You left it out.

class Hand {
....
};

--
Scott McPhillips [VC++ MVP]

Jan 28 '07 #5

P: n/a
I V
On Sun, 28 Jan 2007 14:21:35 -0700, Ed Dana wrote:
OK, I gots a mystery on my hands. I'm hoping someone can tell me just
what the **** is going on here.
class Hand {
[...]
}
^ Note the lack of a semicolon here. That might cause mysterious
problems immediately after where Hand.h is included.
Jan 28 '07 #6

P: n/a
gw****@aol.com wrote:
>>================================================ ======================
#ifndef _Hand_H_
#define _Hand_H_

#include "Card.h"

class Hand {
public:
Hand();

bool add(Card prmCard);
bool canDouble();
bool canSplit();
int getSize();
int getValue();
bool isBlackjack();
bool isBusted();
bool isSoft();
void setHidden(int prmHideNo);
string toString();
string toString(bool prmLong);

private:
bool clsSoft;
int clsCount;
int clsHidden;
Card clsCards[0];
} <-- Semicolon here


Here's your real problem. You need a semi-colon here, and you haven't
put one in.
Blast! I knew it was going to be something annoyingly simple like that.
:) Thanks for the help, that definitely fixed the problem.

Ed.
Jan 28 '07 #7

P: n/a
Ed Dana wrote:
>[redacted]
================================================== ====================
#ifndef _Hand_H_
#define _Hand_H_
Others have pointed out the error of the missing semicolon, so I'll go
with one of my pet peeves.

Your include guard is invalid. The Standard states that any identifier
with a leading underscore followed by an uppercase letter is reserved to
the implementation.

That means your compiler vendor (and the Standard Library vendor, if
they're not the same entity) can use an identifier such as _Hand_H_, but
*YOU* may not.

Just use HAND_H_ as your include guard.
Jan 29 '07 #8

P: n/a
I wrote one for an intro C++ class a few years back. It's probably
horrible (I wasn't much of a coder back then), but if it gives you some
ideas. http://resume.technoplaza.net/c/blackjack.php

The source is included, though it will only compile with MSVC 6. (No,
not MSVC .NET -- it uses MFC stuff that is outdated).

--John Ratliff

Jan 29 '07 #9

P: n/a
On Jan 29, 1:04 pm, red floyd <no.s...@here.dudewrote:
one of my pet peeves.

Your include guard is invalid. The Standard states that any identifier
with a leading underscore followed by an uppercase letter is reserved to
the implementation.

That means your compiler vendor (and the Standard Library vendor, if
they're not the same entity) can use an identifier such as _Hand_H_, but
*YOU* may not.

Just use HAND_H_ as your include guard.
Identifiers in uppercase starting with E are reserved for
future use by errno.h. So this technique will not work
for files starting with 'e'.
Jan 29 '07 #10

P: n/a
Old Wolf wrote:
On Jan 29, 1:04 pm, red floyd <no.s...@here.dudewrote:
>one of my pet peeves.

Your include guard is invalid. The Standard states that any identifier
with a leading underscore followed by an uppercase letter is reserved to
the implementation.

That means your compiler vendor (and the Standard Library vendor, if
they're not the same entity) can use an identifier such as _Hand_H_, but
*YOU* may not.

Just use HAND_H_ as your include guard.

Identifiers in uppercase starting with E are reserved for
future use by errno.h. So this technique will not work
for files starting with 'e'.

Good point. I don't have ISO/IEC 9899 around, so I forgot about that
part, which was included in 14882 by incorporation.

Maybe if for a a generic include guard:

#ifndef IG_FILENAME_H_ /* IG stands for "Include Guard" */
#define IG_FILENAME_H_

// source

#endif
Jan 30 '07 #11

P: n/a
red floyd wrote:
Old Wolf wrote:
>Identifiers in uppercase starting with E are reserved for
future use by errno.h. So this technique will not work
for files starting with 'e'.

Good point. I don't have ISO/IEC 9899 around, so I forgot about that
part, which was included in 14882 by incorporation.

Maybe if for a a generic include guard:

#ifndef IG_FILENAME_H_ /* IG stands for "Include Guard" */
#define IG_FILENAME_H_

// source

#endif

How about just DEF_FILENAME_H?

Just a thought.

Ed.
Jan 30 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.