如何在C ++中共享两个类的属性?

时间:2019-04-23 18:47:54

标签: c++

我在使用C ++中两个类之间的属性时遇到问题。我创建了两个类:Board和Player。 在Board类中,我具有以下功能: Decision makeMove(Move *move, Player::Side side); 我需要将以下类型的变量作为参数传递: enum Side{BLACK,WHITE}; Side side; 在文件下方的Player类中。

我添加了错误:

Engine.h:55:35: error: ‘Player’ has not been declared
     Decision makeMove(Move *move, Player::Side side);
                                   ^~~~~~
Engine.h:55:48: error: expected ‘,’ or ‘...’ before ‘side’
     Decision makeMove(Move *move, Player::Side side);
                                                ^~~~
Engine.h:56:36: error: ‘Player’ has not been declared
     vector <Move*>getAllValidMoves(Player::Side side);
                                    ^~~~~~
Engine.h:56:49: error: expected ‘,’ or ‘...’ before ‘side’
     vector <Move*>getAllValidMoves(Player::Side side);
                                                 ^~~~

这些是董事会和玩家类:

class Board {
private:
    enum Type {EMPTY, WHITE, BLACK, WHITE_KING, BLACK_KING};
    vector<Type>cell;
    vector<vector<Type>>board;
    int numWhiteNormalPieces;
    int numBlackNormalPieces;
    int numBlackKingPieces;
    int numWhiteKingPieces;
public:
    enum Decision {COMPLETED,FAILED_MOVING_INVALID_PIECE,FAILED_INVALID_DESTINATION,ADDITIONAL_MOVE,GAME_ENDED};
public:
    Board();
    Board(vector<vector<Type>>board);      
    Type getPiece(int row, int col);
    Type getPiece(Point *point);
    vector<vector<Type>>getBoard();
    int getNumWhitePieces();
    int getNumBlackPieces();
    int getNumWhiteKingPieces();
    int getNumBlackKingPieces();
    int getNumWhiteNormalPieces();
    int getNumBlackNormalPieces();
    Decision makeMove(Move *move, Player::Side side);
    vector <Move*>getAllValidMoves(Player::Side side);
    // Point* findMidSquare(Move *move);
    // bool isMovingOwnPiece(int row, int col, Player::Side side);
    // vector <Move*>getValidMoves(int row, int col, Player::Side side);
    // vector <Move*>getValidSkipMoves(int row, int col, Player::Side side);
    // bool isOpponentPiece(Player::Side current, Type opponentPiece);
    Board clone();
    // bool contains(vector<Move*> possibleMoves,Move *move);
private: 
    void setUpBoard();
    void setUpTestBoard();
    void populateEmptyOnBoard();  
};
class Player {
public:
    string name;      
    enum Side{BLACK,WHITE};
    Side side;
    Player(string name, Side side);
    Player(Side side);
    Board::Decision makeMove(Move *m, Board b);
    Board::Decision makeRandomMove(Board b);
    string toString();      
};

我需要能够访问这些类的属性,而不管它们在文件中的放置顺序。 (如Java或C#)

0 个答案:

没有答案