VC++ not recognizing 'GameBoard' in code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Huyvtq

    #1

    VC++ not recognizing 'GameBoard' in code

    I have a class Chess with the contructor:
    Chess(const GameBoard& argGameBoard,in t,int,Color,int ); //line 1
    and a property:
    GameBoard& mGameBoard; //line 2

    to creat a reference to one obj of
    GameBoard: :mGameBoard(arg GameBoard) at constructor.

    But when It's compiled (by VC2005++). This errors occured:
    at line 1

    1>e:\vc2005\che ssgame\src\Ches s.h(34) : error C2059: syntax error :
    '<cv-qualifer>'
    1>e:\vc2005\che ssgame\src\Ches s.h(34) : error C2238: unexpected
    token(s) preceding ';'



    and at line 2:
    1>e:\vc2005\che ssgame\src\Ches s.h(69) : error C2143: syntax error :
    missing ';' before '&'
    1>e:\vc2005\che ssgame\src\Ches s.h(69) : error C4430: missing type
    specifier - int assumed. Note: C++ does not support default-int

    It seem that Compiler don't know what GameBoard is in class Chess.
    Here class GameBoard I have defined and included. It have a property:
    Stack<TurnHisto ry>& aReport;

    Who can tell me what it is?

    Tks a lot!

  • Huyvtq

    #2
    Re: VC++ not recognizing 'GameBoard' in code

    Chess(const GameBoard& argGameBoard,in t,int,Color,int ); //line 1

    There're clearly no syntax errors in this line.

    Comment

    • Kai-Uwe Bux

      #3
      Re: VC++ not recognizing 'GameBoard' in code

      Huyvtq wrote:
      Chess(const GameBoard& argGameBoard,in t,int,Color,int ); //line 1
      >
      There're clearly no syntax errors in this line.
      Right. If your compiler complains about this line, you should consider
      filing a bug report.

      Now, on second thought, whether there is an error on that line actually
      depends on a lot of context in the ambient code. The line you posted is the
      line where the compiler decided it has enough information to report an
      error, it is not necessarily the line where the error is located. Maybe,
      your compiler is right, but alas, we have no chance to tell given just this
      one line.


      Best

      Kai-Uwe Bux

      Comment

      • Huyvtq

        #4
        Re: VC++ not recognizing 'GameBoard' in code

        class Chess //abstract Class
        {

        public:
        Chess(const GameBoard& argGameBoard,in t,int,Color,int );

        virtual bool tryToMove(const Point& aPoint);

        void setCurrentPoint (int x,int y);
        Point getCurrentPoint () const;

        int getColor() const
        {
        return mColor;
        }

        int getIdx(){
        return mIdx;
        }

        char getDisplayChara cter(){
        return mDisplay;
        }

        protected:

        const GameBoard& mGameBoard;

        Point mCurrentPoint;

        Color mColor;

        char mDisplay;

        int mIdx;
        };

        Chess::Chess(Ga meBoard& argGameBoard,in t x,int y,Color argColor,int
        argIdx):mGameBo ard(argGameBoar d)
        {
        setCurrentPoint (x,y);
        mColor=argColor ;
        mIdx=argIdx;
        }

        ............... .....

        These're all relative code. Hope you will help me :(
        Tks in advantage!

        Comment

        • Ian Collins

          #5
          Re: VC++ not recognizing 'GameBoard' in code

          Huyvtq wrote:
          class Chess //abstract Class
          {
          >
          public:
          Chess(const GameBoard& argGameBoard,in t,int,Color,int );
          >
          const GameBoard& here

          <snip>
          >
          Chess::Chess(Ga meBoard& argGameBoard,in t x,int y,Color argColor,int
          argIdx):mGameBo ard(argGameBoar d)
          Not const here.
          {
          setCurrentPoint (x,y);
          mColor=argColor ;
          mIdx=argIdx;
          Why not use initialisers for these?


          Are you sure at least a declaration of GameBoard is visible to the compiler?

          --
          Ian Collins.

          Comment

          • Huyvtq

            #6
            Re: VC++ not recognizing 'GameBoard' in code

            On Sep 16, 4:38 pm, Ian Collins <ian-n...@hotmail.co mwrote:
            Huyvtq wrote:
            class Chess //abstract Class
            {
            >
            public:
            Chess(const GameBoard& argGameBoard,in t,int,Color,int );
            >
            const GameBoard& here
            >
            <snip>
            >
            >
            >
            Chess::Chess(Ga meBoard& argGameBoard,in t x,int y,Color argColor,int
            argIdx):mGameBo ard(argGameBoar d)
            >
            Not const here.
            >
            {
            setCurrentPoint (x,y);
            mColor=argColor ;
            mIdx=argIdx;
            >
            Why not use initialisers for these?
            >
            Are you sure at least a declaration of GameBoard is visible to the compiler?
            >
            --
            Ian Collins.
            I tried. But it still like that.
            The problem seem that Compiler doesnt know what GameBoard is although
            I've define & included it
            :(

            Comment

            • Huyvtq

              #7
              Re: VC++ not recognizing 'GameBoard' in code

              Code of GameBoard.h

              #ifndef GAMEBOARD_H
              #define GAMEBOARD_H

              #include "Chess.h"
              #include "TurnHistor y.h"
              #include "Stack.h"
              #include <iostream>
              using namespace std;

              const int kBoardWidth=8;
              const int kBoardHeight=8;

              class GameBoard
              {
              public:
              GameBoard(Stack <TurnHistory>&) ;
              ~GameBoard();
              bool move(const Point&,const Point&);
              // tro Point den chessArr[int]
              void setChess(const Point&,int);
              Chess& getChess(const Point&) const;
              void drawBoard() const;
              bool getIsEnd() const;

              private:
              Chess* chessPtr[kBoardWidth][kBoardHeight];
              Chess* chessArray[32];
              bool isEnd;
              Stack<TurnHisto ry>& aReport;
              };

              #endif

              Comment

              • Ian Collins

                #8
                Re: VC++ not recognizing 'GameBoard' in code

                Huyvtq wrote:
                Code of GameBoard.h
                >
                #ifndef GAMEBOARD_H
                #define GAMEBOARD_H
                >
                #include "Chess.h"
                This doesn't define the Chess class by any chance, does it? If so, all
                bets are off and you will have to look at using forward declarations for
                each class in the other's header.
                using namespace std;
                >
                Never, ever do this in a header! Any file that included the header is
                stuck with this declaration.

                --
                Ian Collins.

                Comment

                • Huyvtq

                  #9
                  Re: VC++ not recognizing 'GameBoard' in code

                  Tks so muchhhhhhhhhh ^^^^^^^^^^^^^^^ ^^^^^^^

                  I used the forward declarations, and it worked ^^
                  But I don't know what is different b/t forward declarations and
                  include?? Why do we have to use forward declarations here?

                  Comment

                  • tragomaskhalos

                    #10
                    Re: VC++ not recognizing 'GameBoard' in code

                    On 16 Sep, 12:02, Huyvtq <huy...@gmail.c omwrote:
                    Tks so muchhhhhhhhhh ^^^^^^^^^^^^^^^ ^^^^^^^
                    >
                    I used the forward declarations, and it worked ^^
                    But I don't know what is different b/t forward declarations and
                    include?? Why do we have to use forward declarations here?
                    Because Chess refers to Gameboard and Gameboard refers
                    to Chess, so you have a cyclic dependency. If you examine
                    your original code and trace through the #includes you should
                    be able to see why this doesn't work. A forward declaration
                    breaks the cycle. Again, trace it through and you'll see.

                    As a general rule, irrespective of cyclic dependencies,
                    you should prefer forward declarations in header files
                    whenever the class in question is only used as a pointer
                    or reference.



                    Comment

                    • Ron Natalie

                      #11
                      Re: VC++ not recognizing 'GameBoard' in code

                      Kai-Uwe Bux wrote:
                      Huyvtq wrote:
                      >
                      > Chess(const GameBoard& argGameBoard,in t,int,Color,int ); //line 1
                      >>
                      >There're clearly no syntax errors in this line.
                      >
                      Right. If your compiler complains about this line, you should consider
                      filing a bug report.
                      >
                      Now, on second thought, whether there is an error on that line actually
                      depends on a lot of context in the ambient code. The line you posted is the
                      line where the compiler decided it has enough information to report an
                      error, it is not necessarily the line where the error is located. Maybe,
                      your compiler is right, but alas, we have no chance to tell given just this
                      one line.
                      If that is truly line 1, it's full of erros. Chess and GameBoard
                      aren't defined anywhere.

                      Comment

                      Working...