473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help me, Obi C Kenobi...

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
11 1719
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

[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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
0
by: Raconteur | last post by:
Hi gang, Very sorry if this is in the wrong place, but I am at my wits end with this thing and am in DESPERATE need of some assistance, ANY assistance... I have a Service that I wrote that...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.