An class structure issue

This is a discussion on An class structure issue within the C++ Programming forums, part of the General Programming Boards category; Hi, this has been annoying me for a few hours, I can't figure out this problem. First, here is the ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    25

    Red face An class structure issue

    Hi, this has been annoying me for a few hours, I can't figure out this problem. First, here is the code that the error is concerned with one file that I will copy and paste here:

    file 1: piece.h
    Code:
    #ifndef PIECE_H
    #define PIECE_H
    
    #include "board.h"
    
    class Piece
    {
        public:
            Piece();
            Piece(int pieceType, int pieceColor, HDC theHdc, Board theB);
            Piece(Piece& origVal);
            Piece& operator=( Piece & origVal);
    
            Board theBoard;
            int ycoord[4], xcoord[4];
            int pieceColor, pieceType;
            int currentOrient;
            HDC hdc;
    };
    #endif
    The error is on the two bolded lines:
    on the first bolded line, I get the following two errors:
    type specifier omitted for parameter
    and
    parse error before `)'

    And the error on the second bolded line is:
    syntax error before `;'

    I'm assuming both of these errors have to do with defining a Board object. I have even included the board.h on the top of this file as you can see.

    board.h is not getting any errors. Can someone tell me what could be going on? I'm confused. Thank you in advance for the help!

    Nimit

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Well you are using the type HDC without defining it. You must include windows.h to use that type of identifier. As far as the Board class goes, try prototyping the class prior to defining it, so something like this:

    Code:
    #ifndef PIECE_H
    #define PIECE_H
    
    class Board; // class prototype
    
    class Piece
    {
      // blah
      // blah
    
      Board theBoard;
    };
    
    #endif /* PIECE_H */

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    25
    Thanks, the prototyping worked out well!

    Nimit

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by MrWizard
    As far as the Board class goes, try prototyping the class prior to defining it, so something like this:

    Code:
    #ifndef PIECE_H
    #define PIECE_H
    
    class Board; // class prototype
    
    class Piece
    {
      // blah
      // blah
    
      Board theBoard;
    };
    
    #endif /* PIECE_H */
    Actually, that really shouldn't fix the board because the piece class holds an actual instance of the board class -- not a pointer or reference, so it actually needs to know the size of the class not just the declaration. In this case you'd actually have to define the class prior (which is probably being done in board.h which is already included).

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    Also, you should surround your board.h include in an ifndef/endif directive. And try to avoid having parameters to functions having the same names as the classes variables:

    Piece(int pieceType, int pieceColor, HDC theHdc, Board theB);

    to

    Piece(int aPieceType, int aPieceColor, HDC theHdc, Board theB);

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    25
    Originally posted by Polymorphic OOP
    Actually, that really shouldn't fix the board because the piece class holds an actual instance of the board class -- not a pointer or reference
    Hey, thats true, but when I said that it worked out, I had also changed the variable to a pointer to Board, not an actual board object, so it did work out well thanks for all your help!

    Nimit

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with pointers to an abstract class and inheritance
    By bainevii in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2009, 07:51 AM
  2. structure vs. class
    By $l4xklynx in forum C++ Programming
    Replies: 7
    Last Post: 01-22-2009, 02:00 AM
  3. Abstract class (IDispatch) in a C structure
    By Overlord in forum Windows Programming
    Replies: 4
    Last Post: 12-31-2008, 07:38 AM
  4. Problem with structure and class
    By Bargi in forum C++ Programming
    Replies: 3
    Last Post: 09-25-2007, 02:30 AM
  5. Converting a C structure into a C++ class
    By deadpoet in forum C++ Programming
    Replies: 7
    Last Post: 01-07-2004, 01:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21