Help me, Obi C Kenobi...

Discussion in 'C++' started by Ed Dana, Jan 28, 2007.

  1. Ed Dana

    Ed Dana Guest

    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.
     
    Ed Dana, Jan 28, 2007
    #1
    1. Advertising

  2. Ed Dana

    Ian Collins Guest

    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.
     
    Ian Collins, Jan 28, 2007
    #2
    1. Advertising

  3. Ed Dana

    Guest

    [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 <> 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.
    >
    > 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, 2007
    #3
  4. 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
     
    Thomas J. Gritzan, Jan 28, 2007
    #4
  5. 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]
     
    Scott McPhillips [MVP], Jan 28, 2007
    #5
  6. Ed Dana

    I V Guest

    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.
     
    I V, Jan 28, 2007
    #6
  7. Ed Dana

    Ed Dana Guest

    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.
     
    Ed Dana, Jan 28, 2007
    #7
  8. Ed Dana

    red floyd Guest

    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.
     
    red floyd, Jan 29, 2007
    #8
  9. Ed Dana

    John Ratliff Guest

    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
     
    John Ratliff, Jan 29, 2007
    #9
  10. Ed Dana

    Old Wolf Guest

    On Jan 29, 1:04 pm, red floyd <> wrote:
    > 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'.
     
    Old Wolf, Jan 29, 2007
    #10
  11. Ed Dana

    red floyd Guest

    Old Wolf wrote:
    > On Jan 29, 1:04 pm, red floyd <> wrote:
    >> 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
     
    red floyd, Jan 29, 2007
    #11
  12. Ed Dana

    Ed Dana Guest

    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.
     
    Ed Dana, Jan 30, 2007
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?dHJlbGxvdzQyMg==?=

    HELP! HELP! HELP! Opening Web Application Project Error

    =?Utf-8?B?dHJlbGxvdzQyMg==?=, Feb 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    776
    =?Utf-8?B?dHJlbGxvdzQyMg==?=
    Feb 20, 2004
  2. Harvey
    Replies:
    0
    Views:
    721
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    856
    Daniel
    Jul 16, 2004
  4. =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=

    HELP - HELP - HELP

    =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=, Mar 9, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    688
    Eliyahu Goldin
    Mar 9, 2006
  5. Frogleg

    Help me, Obi-Wan Kenobi

    Frogleg, Jun 16, 2004, in forum: HTML
    Replies:
    15
    Views:
    651
Loading...

Share This Page