Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ ';类别';不命名类型_C++_Constructor_Header - Fatal编程技术网

C++ ';类别';不命名类型

C++ ';类别';不命名类型,c++,constructor,header,C++,Constructor,Header,董事会 Board.cpp #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 告诉我错误:“Board”没有命名类型。 用gcc编译它 编辑: 我注释掉#include“piece

董事会

Board.cpp

#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
告诉我错误:“Board”没有命名类型。 用gcc编译它

编辑:

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

#include "Board.h"

Board::Board(bool fill)
{
...
};

代码很好。我猜这个错误是由于“piece.h”中潜藏了一些东西
piece.h
包含什么?让我们看看内容。似乎是循环的
#includes
piece.h
是否包含对
板的引用或其他有趣的内容?故障可能在那里。分号
,错误指向的是哪个文件的哪一行?为什么要用GCC编译
.cpp
它?这不是问题的解决方案,应该是注释而不是答案。但是考虑到问题在于未提供的一段代码这是最接近可能给出的答案。他是对的。在我注释掉该包含内容后编译的代码。
#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