'Class'不命名类型

'Class' does not name a type

本文关键字:类型 Class      更新时间:2023-10-16

Board.h

#ifndef BOARD_H
#define BOARD_H
#include "piece.h"

class Board
{
    public:
        Board(bool);
        //Piece * getPiece(int x, int y){return &pieceboard[x][y];}
};
#endif

板.cpp

#include "Board.h"
Board::Board(bool fill)
{
...
};

给我一个错误:"Board"没有命名类型。用gcc编译。

编辑:

在我注释掉#include"piece.h"后编译的代码。显然它有一些未声明的类。

#ifndef PIECE_H
#define PIECE_H
#include "Board.cpp"
class Piece{
    public:
        virtual bool checkMove(int, int) =0;
        bool movePiece(int, int);
        int getX(){return x;}
        int getY(){return y;}
        char getChar(){return image;}
        bool getWhite(){return isWhite;}
    protected:
        int x, y;
        char image;
        bool isWhite;
    };
    class Pawn : public Piece{
    public:
        Pawn(bool, int, int, Board); // ERROR: 'Board' has not been declared
        bool checkMove(int, int);
    private:
        Board * board; };            // ERROR: 'Board' does not name a type
#endif

代码很好。我想这个错误是由于"piece.h"中隐藏的东西造成的